





CREATE DATABASE spidd;

USE spidd;

ALTER DATABASE SPIDD DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE BAREME (
	BAR_CD			VARCHAR(5)	   NOT NULL,
	BAR_LB			VARCHAR(32)	   NOT NULL,
	BAR_LB_COURT		VARCHAR(5)	   NULL,
	BAR_ID			BIGINT		 NOT NULL,
	ORGA_ID			BIGINT		 NOT NULL,
	BAR_NB_JOUEUR		INT			 NULL,
	BL_MAJ			SMALLINT		 NULL
);

ALTER TABLE BAREME ADD PRIMARY KEY PK_BAREME (BAR_ID);

CREATE TABLE ORGANISME (
	ORGA_ID			BIGINT		 NOT NULL,
	ORG_ORGA_ID		BIGINT		 NULL,
	ORGA_LB			VARCHAR(32)	   NOT NULL,
	ORGA_CD			VARCHAR(5)	   NOT NULL,
	ORGA_FG			CHAR(1)		   NOT NULL,
	ORGA_BL_MODULE	SMALLINT		 NOT NULL,
	BL_MAJ			SMALLINT		 NULL
);


ALTER TABLE ORGANISME ADD PRIMARY KEY PK_ORGANISME (ORGA_ID);

	CREATE TABLE BAREME_DETAIL (
	DBAR_ID_DETAILS		BIGINT	 NOT NULL,
	DBAR_NB_PLACE			INT		 NOT NULL,
	DBAR_NB_POINT			INT		 NOT NULL,
	BAR_ID				BIGINT	 NOT NULL,
	BL_MAJ				SMALLINT	 NULL
) ;


ALTER TABLE BAREME_DETAIL ADD   PRIMARY KEY PK_BAREME_DETAIL (DBAR_ID_DETAILS);

CREATE TABLE CAT (
	CAT_ID		BIGINT		 NOT NULL,
	GCAT_CD		CHAR(5)		  NOT NULL,
	CAT_LB		VARCHAR(32)	  NOT NULL,
	CAT_CD		VARCHAR(5)	  NOT NULL,
	CAT_DT_DEB	DATETIME		 NOT NULL,
	CAT_DT_FIN	DATETIME		 NOT NULL,
	CAT_FG		CHAR(1)		  NOT NULL,
	DEM_ID		BIGINT		 NULL,
	BL_MAJ		SMALLINT		 NULL
) ;

ALTER TABLE CAT ADD   PRIMARY KEY PK_CAT (CAT_ID);

CREATE TABLE CAT_AGE_GROUP (
	GCAT_CD			CHAR(5)		  NOT NULL,
	GCAT_LB_COURT		VARCHAR(5)	  NOT NULL,
	GCAT_LB			VARCHAR(32)	  NOT NULL,
	BL_MAJ			SMALLINT		 NULL
) ;



ALTER TABLE CAT_AGE_GROUP ADD   PRIMARY KEY PK_CAT_AGE_GROUP (GCAT_CD);


CREATE TABLE CAT_SPORT (
	CAT_SPORT_ID		BIGINT		 NOT NULL,
	CAT_LB			VARCHAR(32)	  NOT NULL,
	CAT_CD			VARCHAR(5)	  NOT NULL,
	CAT_DT_DEB		DATETIME		 NOT NULL,
	CAT_DT_FIN		DATETIME		 NOT NULL,
	CAT_FG			CHAR(1)		  NOT NULL,
	BL_MAJ			BIT			 NULL DEFAULT 0
) ;
	
ALTER TABLE CAT_SPORT ADD   PRIMARY KEY PK_CAT_SPORT (CAT_SPORT_ID);

CREATE TABLE CATEGORIE_EPREUVE (
	DIV_ID					BIGINT NOT NULL,
	CAT_ID					BIGINT NOT NULL,
	CAT_EPR_BL_PRINCIPAL		BIT	 NULL
) ;



ALTER TABLE CATEGORIE_EPREUVE ADD   PRIMARY KEY PK_CATEGORIE_EPREUVE (DIV_ID, CAT_ID);




CREATE TABLE DIVISION (
	DIV_ID					BIGINT		 NOT NULL,
	ORGA_ID					BIGINT		 NOT NULL,
	EPRV_ID					BIGINT		 NOT NULL,
	DIV_CD					VARCHAR(5)	  NOT NULL,
	DIV_LB					VARCHAR(32)	  NOT NULL,
	DIV_NB_POULE				INT			 NOT NULL,
	DIV_FG_SEXE				CHAR(1)		  NOT NULL,
	DIV_FG_TYPE_LICENCE		CHAR(1)		  NOT NULL,
	DIV_BL_CORPO				SMALLINT		 NOT NULL,
	DIV_NB_TOUR				SMALLINT		 NULL,
	DIV_CD_LETTRE				CHAR(1)		  NOT NULL,
	DIV_CM					VARCHAR(255)	  NULL,
	DIV_LB_USER_MODIF			VARCHAR(15)	  NOT NULL,
	BAR_ID					BIGINT		 NULL,
	GCAT_CD					CHAR(5)		  NULL,
	DIV_DIV_ID				BIGINT		 NULL,
	DIV_BL_DOUBLE				SMALLINT		 NULL,
	DIV_NB_POINT_MANCHE		INT			 NOT NULL,
	DIV_NB_MANCHE_POULE		INT			 NOT NULL,
	DIV_NB_MANCHE_TAB			INT			 NOT NULL,
	DIV_NB_POINT_MIN			INT			 NOT NULL,
	DIV_NB_POINT_MAX			INT			 NOT NULL,
	DIV_DT_TOUR				DATETIME		 NULL
) ;



ALTER TABLE DIVISION ADD PRIMARY KEY PK_DIVISI (DIV_ID);



CREATE TABLE EPREUVE (
	EPRV_ID				BIGINT		 NOT NULL,
	ORGA_ID				BIGINT		 NOT NULL,
	EPR_EPRV_ID			BIGINT		 NULL,
	EPRV_CD				CHAR(2)		  NOT NULL,
	EPRV_LB_COURT			VARCHAR(5)	  NOT NULL,
	EPRV_LB				VARCHAR(32)	  NOT NULL,
	EPRV_FG				CHAR(1)		  NOT NULL,
	EPRV_CM				VARCHAR(255)	  NULL,
	EPRV_LB_USER_MODIF	VARCHAR(15)	  NOT NULL
) ;



ALTER TABLE EPREUVE ADD   PRIMARY KEY PK_EPREUVE (EPRV_ID);



CREATE TABLE CELLULE_POT (
	CELLULE_ID			BIGINT		 NOT NULL,
	LIGNE_POT_ID			BIGINT		 NOT NULL,
	TABPART_ID_TABLEAU	BIGINT		 NULL,
	CELL_NM_TABLE			INT			 NULL,
	CELL_LB_PARTIE		VARCHAR(64)	  NULL,
	CELL_CODE_ROUGE		INT			 NULL,
	CELL_CODE_VERT		INT			 NULL,
	CELL_CODE_BLEU		INT			 NULL
) ;


ALTER TABLE CELLULE_POT ADD   PRIMARY KEY PK_CELLULE_POT (CELLULE_ID);



CREATE TABLE LIGNE_POT (
	LIGNE_POT_ID			BIGINT		 NOT NULL,
	POT_ID				BIGINT		 NOT NULL,
	LIGNE_POT_NM_ORDRE	INT			 NOT NULL,
	LIGNE_POT_LB			VARCHAR(32)	  NULL,
	LIGNE_POT_NB_TABLE	INT			 NULL
) ;


ALTER TABLE LIGNE_POT ADD   PRIMARY KEY PK_LIGNE_POT (LIGNE_POT_ID);






CREATE TABLE POT (
	POT_ID				BIGINT		 NOT NULL,
	POT_LB				VARCHAR(32)	  NOT NULL,
	POT_DT				DATETIME		 NOT NULL  DEFAULT '1900-01-01 00:00:00',
	POT_NB_TABLE			INT			 NULL,
	POT_NB_TRANCHE		INT			 NULL,
	POT_HEURE				INT			 NULL,
	POT_MINUTE			INT			 NULL,
	POT_NB_INTERVALLE		INT			 NULL,
	POT_NB_TABLE_MAX		INT			 NULL,
	POT_POT_ID			BIGINT		 NULL
) ;





ALTER TABLE POT ADD   PRIMARY KEY PK_POT (POT_ID);





CREATE TABLE TABLEAU_PARTIE (
	TABPART_ID_TABLEAU			BIGINT		 NOT NULL,
	POUL_ID						BIGINT		 NULL,
	NIV_ID						BIGINT		 NULL,
	INSC_ID						BIGINT		 NULL,
	INS_INSC_ID					BIGINT		 NULL,
	PARTI_ID						BIGINT		 NULL,
	TABPART_NM_ORDRE_NIVEAU		INT			 NULL,
	TABPART_NM_TABLEAU			INT			 NULL,
	TABPART_NM_VAINQUEUR			INT			 NULL,
	TABPART_DT_HEURE				DATETIME		 NOT NULL,
	TABPART_NB_TABLE				CHAR(5)		  NULL,
	RPARTI_ID_PARTIE_REF			BIGINT		 NULL,
	TABPART_TYPE_PARTIE			SMALLINT		 NULL,
	TABPART_NM_PERDANT			INT			 NULL,
	TABPART_LB_PARTIE				VARCHAR(10)	  NULL,
	TABPART_BL_CLST				SMALLINT		 NULL DEFAULT 0
) ;




ALTER TABLE TABLEAU_PARTIE ADD   PRIMARY KEY PK_TABLEAU_PARTIE (TABPART_ID_TABLEAU);


CREATE TABLE INSCRIPTION (
	INSC_ID						BIGINT	 NOT NULL,
	JOUE_ID						BIGINT	 NOT NULL,
	TOUR_ID						BIGINT	 NOT NULL,
	INSC_NB_DOSSARD				INT		 NOT NULL,
	INSC_NB_RANG_POULE			INT		 NOT NULL,
	INSC_NB_POINT_TOUR			INT		 NULL,
	INSC_BL_ABSENT				SMALLINT	 NOT NULL,
	POUL_ID						BIGINT	 NULL,
	TOUR_ID_PREC					BIGINT	 NULL,
	INSC_NB_RANG_TOUR				INT		 NULL,
	INSC_NM_RANG_TABLEAU			INT		 NULL,
	INSC_CD_LETTRE				CHAR(1)	  NULL,
	TAB_ID						BIGINT	 NULL,
	INSC_BL_TETE_SERIE			SMALLINT	 NULL,
	INSC_NM_CLASSEMENT			INT		 NULL,
	INSC_TIRAGE_POS_TAB			INT		 NULL,
	INSC_BL_TIRAGE_TETE_SERIE		SMALLINT	 NULL
) ;


ALTER TABLE INSCRIPTION ADD  PRIMARY KEY PK_INSCRIPTI (INSC_ID);


CREATE TABLE JOUEUR (
	JOUE_ID					BIGINT		 NOT NULL,
	EPRV_ID					BIGINT		 NOT NULL,
	LIC_ID					BIGINT		 NOT NULL,
	JOUE_NB_POINT_TOTAL		VARCHAR(64)	  NULL,
	JOUE_BL_FORFAIT_GENE		INT			 NOT NULL,
	JOUE_LB_TRI_POINT			VARCHAR(64)	  NULL
) ;


ALTER TABLE JOUEUR ADD   PRIMARY KEY PK_JOUEUR (JOUE_ID);




CREATE TABLE LICENCIE (
	LIC_ID						BIGINT		 NOT NULL,
	CAT_ID						BIGINT		 NULL,
	CLUB_ID						BIGINT		 NULL,
	CLU_CLUB_ID					BIGINT		 NULL,
	TCLST_ID						BIGINT		 NULL,
	PERS_LB_NOM					VARCHAR(64)	  NULL,
	PERS_LB_PRENOM				VARCHAR(15)	  NULL,
	PERS_FG_SEXE					CHAR(1)		  NULL,
	PERS_DT_NAISSANCE				DATETIME		 NULL,
	LIC_NB_LICENCE				VARCHAR(8)	  NULL,
	LIC_FG_NATIONALITE			CHAR(1)		  NULL,
	LIC_FG						CHAR(1)		  NULL,
	LIC_FG_MODULE					CHAR(1)		  NULL,
	LIC_FG_CERTIFICAT				CHAR(1)		  NULL,
	LIC_DT_CERTIFICAT				DATETIME		 NULL,
	LIC_DT_VALIDATION				DATETIME		 NULL,
	LIC_NB_PLACE					INT			 NULL,
	LIC_NB_POINT					NUMERIC(7, 3)	 NULL,
	LIC_FG_ECHELON				CHAR(1)		  NULL,
	LIC_NB_POINT_CF_PREC			VARCHAR(64)	  NULL,
	LIC_NB_POINT_TOTAL_CF			VARCHAR(64)	  NULL,
	LIC_NB_TRI_POINT_CF			VARCHAR(64)	  NULL,
	LIC_BL_LOCAL					SMALLINT		 NULL,
	LIC_BL_DOUBLE					SMALLINT		 NULL,
	LIC_NB_TOTAL_POINT_DOUBLE		NUMERIC(7, 3)	 NULL,
	LIC_NB_POINT_TOUR_PREC_CF		VARCHAR(64)	  NULL,
	EPRV_ID						BIGINT		 NULL,
	DOUBLE_CLUB_ID				BIGINT		 NULL,
	DOUBLE_CLU_CLUB_ID			BIGINT		 NULL,
	CAT_SPORT_ID					BIGINT		 NULL
) ;

CREATE INDEX LICENCIE_NOM_INDX ON LICENCIE (PERS_LB_NOM);

CREATE INDEX LICENCIE_NUMERO_INDX ON LICENCIE (LIC_NB_LICENCE);

ALTER TABLE LICENCIE ADD   PRIMARY KEY PK_LICENCIE (LIC_ID);





CREATE TABLE CLUB (
	CLUB_ID			BIGINT		 NOT NULL,
	ORGA_ID			BIGINT		 NULL,
	CLUB_NM			VARCHAR(8)	  NOT NULL,
	CLUB_LB_LONG		VARCHAR(32)	  NOT NULL,
	CLUB_LB_COURT		VARCHAR(15)	  NOT NULL,
	CLUB_FG			CHAR(1)		  NOT NULL
) ;


CREATE INDEX CLUB_NUMERO_INDX ON CLUB(CLUB_NM) ;


ALTER TABLE CLUB ADD   PRIMARY KEY PK_CLUB (CLUB_ID);










CREATE TABLE TYPE_CLASSEMENT (
	TCLST_ID				BIGINT		 NOT NULL,
	TCLST_LB				VARCHAR(32)	  NOT NULL,
	TCLST_CD				CHAR(2)		  NULL,
	TCLST_NB_POINT_MIN	INT			 NOT NULL,
	BL_MAJ				SMALLINT		 NULL
) ;


ALTER TABLE TYPE_CLASSEMENT ADD   PRIMARY KEY PK_TYPE_CLASSEMENT (TCLST_ID);







CREATE TABLE POULE (
	POUL_ID					BIGINT		 NOT NULL,
	GRIL_ID_RENC				BIGINT		 NOT NULL,
	CALEN_ID_SPORTIF			BIGINT		 NULL,
	FEUIL_ID_RENC				BIGINT		 NULL,
	DIV_ID					BIGINT		 NOT NULL,
	POUL_CD					VARCHAR(5)	  NOT NULL,
	POUL_LB					VARCHAR(32)	  NOT NULL,
	POUL_NM_GROUPE			SMALLINT		 NULL,
	POUL_BL_VIRTUEL			SMALLINT		 NOT NULL,
	POUL_DT					DATETIME		 NULL,
	POUL_DT_VALIDATION		DATETIME		 NULL,
	POUL_LB_COMPETIT			VARCHAR(32)	  NULL,
	POUL_LB_USER_MODIF		VARCHAR(15)	  NOT NULL,
	POUL_DT_MODIFICATION		DATETIME		 NULL,
	POUL_DT_CREATION			DATETIME		 NOT NULL,
	TAB_ID					BIGINT		 NULL,
	POUL_NM_TABLEAU			INT			 NULL
) ;


ALTER TABLE POULE ADD   PRIMARY KEY PK_POULE (POUL_ID);



CREATE TABLE GRILLE_RENCONTRE (
	GRIL_ID_RENC			BIGINT		 NOT NULL,
	ORGA_ID				BIGINT		 NOT NULL,
	GRIL_CD_RENC			VARCHAR(5)	  NOT NULL,
	GRIL_LB_RENC			VARCHAR(32)	  NOT NULL,
	GRIL_NB_EQUIPE		INT			 NOT NULL,
	GRIL_FG				CHAR(1)		  NOT NULL,
	GRIL_LB_USER_MODIF	VARCHAR(15)	  NULL DEFAULT 'Default',
	GRIL_DT_CREATION		DATETIME		 NULL DEFAULT '1900-01-01 00:00:00',
	BL_MAJ				SMALLINT		 NULL
) ;




ALTER TABLE GRILLE_RENCONTRE ADD   PRIMARY KEY PK_GRILLE_RENCONTRE (GRIL_ID_RENC);




CREATE TABLE TABLEAU (
	TAB_ID					BIGINT		 NOT NULL,
	TABREF_ID					BIGINT		 NULL,
	TOUR_ID					BIGINT		 NOT NULL,
	TAB_NB_GROUPE				INT			 NOT NULL,
	TAB_CD_TABLEAU			VARCHAR(5)	  NULL,
	TAB_LB					VARCHAR(32)	  NOT NULL,
	TAB_DT_HEURE				DATETIME		 NOT NULL,
	TAB_LB_LIEU				VARCHAR(32)	  NULL,
	TAB_CM_TABLEAU			VARCHAR(255)	  NULL,
	TAB_CM_TABLE_JUGE			VARCHAR(255)	  NULL,
	TAB_LB_RAPPORT			VARCHAR(64)	  NULL,
	TAB_LB_USER_MODIF			VARCHAR(15)	  NOT NULL,
	TAB_DT_MODIFICATION		DATETIME		 NULL,
	TAB_DT_CREATION			DATETIME		 NOT NULL,
	TAB_ALIAS					VARCHAR(30)	  NULL
) ;


ALTER TABLE TABLEAU ADD   PRIMARY KEY PK_TABLEAU (TAB_ID);





CREATE TABLE TABLEAU_REF (
	TABREF_ID					BIGINT		 NOT NULL,
	TABREF_CD					VARCHAR(5)	  NOT NULL,
	TABREF_LB					VARCHAR(32)	  NOT NULL,
	TABREF_FG					CHAR(2)		  NOT NULL,
	TABREF_NB_JOUEURS_REF		INT			 NOT NULL,
	TABREF_CM					VARCHAR(255)	  NULL,
	TABREF_LB_USER_MODIF		VARCHAR(15)	  NOT NULL,
	TABREF_DT_MODIFICATION	DATETIME		 NULL,
	TABREF_DT_CREATION		DATETIME		 NOT NULL,
	TABREF_SAISIE_TYPE		CHAR(1)		  NULL,
	BL_MAJ					SMALLINT		 NULL
) ;


ALTER TABLE TABLEAU_REF ADD CONSTRAINT PK_TABLEAU_REF PRIMARY KEY CLUSTERED (TABREF_ID);




CREATE TABLE TOUR (
	TOUR_ID					BIGINT		 NOT NULL,
	DIV_ID					BIGINT		 NOT NULL,
	TOUR_LB					VARCHAR(32)	  NULL,
	TOUR_NB_GROUPE			INT			 NULL,
	TOUR_NB_POULE				INT			 NULL,
	TOUR_NB_JOUEUR			INT			 NULL,
	TOUR_NB_JOUEUR_DESC		INT			 NULL,
	TOUR_NB_JOUEUR_MONT		INT			 NULL,
	TOUR_DT					DATETIME		 NULL,
	TOUR_LB_USER_MODIF		VARCHAR(15)	  NULL,
	TOUR_DT_MODIFICATION		DATETIME		 NULL,
	TOUR_DT_CREATION			DATETIME		 NULL,
	GRIL_ID_RENC				BIGINT		 NULL,
	TOUR_BL_CLOTURE			SMALLINT		 NULL,
	TOUR_NM					INT			 NULL,
	DIV_DIV_LB				VARCHAR(32)	  NULL,
	DIV2_DIV_LB				VARCHAR(32)	  NULL
) ;


ALTER TABLE TOUR ADD   PRIMARY KEY PK_TOUR (TOUR_ID);





CREATE TABLE NIVEAU (
	NIV_ID			BIGINT	 NOT NULL,
	TAB_ID			BIGINT	 NOT NULL,
	NIVREF_ID			BIGINT	 NOT NULL,
	NIV_DT_HEURE		DATETIME	 NOT NULL,
	NIV_LB_LIEU		CHAR(32)	  NULL,
	NIV_CM			VARCHAR(5)  NULL
) ;


ALTER TABLE NIVEAU ADD   PRIMARY KEY PK_NIVEAU (NIV_ID);



CREATE TABLE NIVEAU_REF (
	NIVREF_ID				BIGINT		 NOT NULL,
	TABREF_ID				BIGINT		 NOT NULL,
	NIVREF_CD				CHAR(5)		  NOT NULL,
	NIVREF_LB				VARCHAR(32)	  NOT NULL,
	NIVREF_NB				INT			 NOT NULL,
	NIVREF_BL_DEPART		SMALLINT		 NULL,
	NIVREF_NIVREF_ID		BIGINT		 NULL,
	BL_MAJ				SMALLINT		 NULL
) ;


ALTER TABLE NIVEAU_REF ADD   PRIMARY KEY PK_NIVEAU_REF (NIVREF_ID);






CREATE TABLE PARTIE (
	PARTI_ID				BIGINT	 NOT NULL,
	LIC_ID				BIGINT	 NOT NULL,
	LIC_LIC_ID			BIGINT	 NOT NULL,
	RENC_ID				BIGINT	 NULL,
	PARTI_NB_ORDRE		INT		 NOT NULL,
	PARTI_BL_GAGNE1		SMALLINT	 NOT NULL,
	PARTI_BL_GAGNE2		SMALLINT	 NOT NULL,
	PARTI_BL_FORFAIT		SMALLINT	 NOT NULL,
	EPRV_ID				BIGINT	 NULL,
	PARTI_BL_SUPPRIMEE	SMALLINT	 NULL,
	PARTI_DT				DATETIME	 NOT NULL,
	PARTI_NM_TOUR			INT		 NULL,
	PARTI_BL_DOUBLE		SMALLINT	 NULL,
	TAB_ID				BIGINT	 NULL,
	PARTI_NB_POINT1		INT		 NULL,
	PARTI_NB_POINT2		INT		 NULL,
	PARTI_BL_CLST			SMALLINT	 NULL,
	PARTI_BL_NONJOUEE		SMALLINT	 NULL
) ;

ALTER TABLE PARTIE ADD   PRIMARY KEY PK_PARTIE (PARTI_ID);


CREATE TABLE PARTIE_REF (
	RPARTI_ID_PARTIE_REF			BIGINT	 NOT NULL,
	NIVREF_ID						BIGINT	 NOT NULL,
	PAR_RPARTI_ID_PARTIE_REF		BIGINT	 NULL,
	PAR2_RPARTI_ID_PARTIE_REF		BIGINT	 NULL,
	RPARTI_NM_RANG1				INT		 NULL,
	RPARTI_NM_RANG2				INT		 NULL,
	RPARTI_NM_ORDRE_REF			INT		 NULL,
	RPARTI_NM_PARTIE_REF			INT		 NULL,
	RPARTI_FG_PARTIE_1			CHAR(1)	  NULL,
	RPARTI_NM_CLST_VAINQUEUR		INT		 NULL,
	RPARTI_NM_POULE1				INT		 NULL,
	RPARTI_NM_CLASSEMENT1			INT		 NULL,
	RPARTI_NM_POULE2				INT		 NULL,
	RPARTI_NM_CLASSEMENT2			INT		 NULL,
	RPARTI_NM_POSITION1			INT		 NULL,
	RPARTI_NM_POSITION2			INT		 NULL,
	RPARTI_FG_PARTIE_2			CHAR(1)	  NULL,
	RPARTI_NM_CLST_PERDANT		INT		 NULL,
	RPARTI_FG_PARTIE_REF			CHAR(1)	  NULL,
	RPARTI_NM_CLST_REF			CHAR(1)	  NULL,
	BL_MAJ						SMALLINT	 NULL,
	RPARTI_BL_CLST_NONJOUEE		SMALLINT	 NULL
) ;


ALTER TABLE PARTIE_REF ADD   PRIMARY KEY PK_PARTIE_REF (RPARTI_ID_PARTIE_REF);



CREATE TABLE CLASSEMENT (
	CLST_ID				BIGINT	 NOT NULL,
	POUL_ID				BIGINT	 NULL,
	CLST_NB_RANG			INT		 NULL,
	CLST_NB_POINTS		INT		 NULL,
	CLST_NB_VICTOIRE		INT		 NULL,
	CLST_NB_DEFAITE		INT		 NULL,
	CLST_NB_EGALITE		INT		 NULL,
	CLST_NB_FORFAITS		INT		 NULL,
	CLST_NB_PENALITE		INT		 NULL,
	CLST_NB_GAGNE			INT		 NULL,
	CLST_NB_PERDUES		INT		 NULL,
	EQUIP_ID				BIGINT	 NULL,
	LIC_ID				BIGINT	 NULL,
	TAB_ID				BIGINT	 NULL,
	CLST_CD_LETTRE		CHAR(1)	  NULL,
	NIV_ID				BIGINT	 NULL,
	CLST_RANG_FORFAIT		CHAR(2)	  NULL
) ;


ALTER TABLE CLASSEMENT ADD   PRIMARY KEY PK_CLASSEMENT (CLST_ID);



CREATE TABLE GRILLE_DETAIL (
	DGRIL_ID_DETAIL		BIGINT	 NOT NULL,
	GRIL_ID_RENC			BIGINT	 NOT NULL,
	DGRIL_NB_JOURNEE		INT		 NOT NULL,
	DGRIL_NB_EQUIPE1		INT		 NOT NULL,
	DGRIL_NB_EQUIPE2		INT		 NOT NULL,
	BL_MAJ				SMALLINT	 NULL
) ;


ALTER TABLE GRILLE_DETAIL ADD   PRIMARY KEY PK_GRILLE_DETAIL (DGRIL_ID_DETAIL);



CREATE TABLE MANCHE (
	MANCH_ID				BIGINT NOT NULL,
	TABPART_ID_TABLEAU	BIGINT NOT NULL,
	MANCH_NB_SCORE1		INT	 NULL,
	MANCH_NB_SCORE2		INT	 NULL,
	MANCH_NB_RANG			INT	 NOT NULL
) ;


ALTER TABLE MANCHE ADD CONSTRAINT PK_MANCHE PRIMARY KEY CLUSTERED (MANCH_ID);





CREATE TABLE PACKAGE (
	PKG_ID					BIGINT		 NOT NULL,
	UTIL_LB_LOGIN				VARCHAR(15)	  NOT NULL,
	PKG_LB					VARCHAR(32)	  NULL,
	PKG_ETAT					CHAR(1)		  NULL,
	PKG_LB_USER_MODIF			VARCHAR(15)	  NULL,
	PKG_DT_MODIFICATION		DATETIME		 NULL,
	PKG_DT_CREATION			DATETIME		 NULL,
	PKG_DATE_DESC				DATETIME		 NULL,
	PKG_DATE_MONTE			DATETIME		 NULL
) ;


ALTER TABLE PACKAGE ADD   PRIMARY KEY PK_PACKAGE (PKG_ID);







CREATE TABLE PACKAGE_TABLEAU (
	PKG_ID	BIGINT NOT NULL,
	TAB_ID	BIGINT NOT NULL
) ;


ALTER TABLE PACKAGE_TABLEAU ADD CONSTRAINT PK_PACKAGE_TABLEAU PRIMARY KEY CLUSTERED (PKG_ID, TAB_ID);








CREATE TABLE PARAMETRE (
	PARM_CD			VARCHAR(20)	  NOT NULL,
	PARM_LB			VARCHAR(32)	  NOT NULL,
	PARM_DT_CREA		DATETIME		 NOT NULL
) ;


ALTER TABLE PARAMETRE ADD   PRIMARY KEY PK_PARM (PARM_CD);



CREATE TABLE POT_TABLEAU (
	POT_ID				BIGINT NOT NULL,
	TAB_ID				BIGINT NOT NULL,
	POTTAB_CODE_ROUGE		INT	 NULL,
	POTTAB_CODE_VERT		INT	 NULL,
	POTTAB_CODE_BLEU		INT	 NULL
) ;

ALTER TABLE pot_tableau ADD   PRIMARY KEY PK_TABLEAU_POT (POT_ID, TAB_ID);



CREATE TABLE SECURITE (
	PROFIL_CD		CHAR(5)		  NOT NULL,
	PROFIL_LB		VARCHAR(32)	  NOT NULL,
	PROFIL_PWD	VARCHAR(32)	  NOT NULL
) ;



ALTER TABLE SECURITE ADD   PRIMARY KEY PK_PROFIL (PROFIL_CD);



CREATE TABLE TIRAGE (
	TIRAGE_ID				BIGINT	 NOT NULL,
	TAB_ID				BIGINT	 NOT NULL,
	TIRAGE_NUM_LIGNE		INT		 NOT NULL,
	TIRAGE_NUM_COLONNE	INT		 NOT NULL,
	TIRAGE_VALEUR			INT		 NULL,
	TIRAGE_BL_QUALIFIE	SMALLINT	 NULL
) ;



ALTER TABLE TIRAGE ADD   PRIMARY KEY PK_TIRAGE (TIRAGE_ID);




CREATE TABLE USER_TAB (
	NM_ORDRE			SMALLINT	 NOT NULL,
	FORM_TYPE			SMALLINT	 NOT NULL,
	TAB_ID			BIGINT	 NULL,
	BL_SHOWMENU		BIT		 NOT NULL DEFAULT 0,
	BL_OPENED			BIT		 NOT NULL DEFAULT 0
) ;


ALTER TABLE USER_TAB ADD   PRIMARY KEY PK_USER_TAB (NM_ORDRE);


ALTER TABLE CELLULE_POT DROP COLUMN CELL_CODE_ROUGE;
ALTER TABLE CELLULE_POT DROP COLUMN CELL_CODE_VERT;
ALTER TABLE CELLULE_POT DROP COLUMN CELL_CODE_BLEU;

ALTER TABLE CELLULE_POT ADD COLUMN CELL_CODE_COULEUR VARCHAR(10)  NULL;

ALTER TABLE POT ADD COLUMN POT_EPRV_FG	CHAR(1) NOT NULL DEFAULT 'I';


ALTER TABLE POT_TABLEAU DROP COLUMN POTTAB_CODE_ROUGE;
ALTER TABLE POT_TABLEAU DROP COLUMN POTTAB_CODE_VERT;
ALTER TABLE POT_TABLEAU DROP COLUMN POTTAB_CODE_BLEU;
	
ALTER TABLE POT_TABLEAU ADD COLUMN POTTAB_CODE_COULEUR	VARCHAR(10)   NULL;

ALTER TABLE TABLEAU ADD COLUMN TAB_BL_REGROUPEMENT BIT NOT NULL DEFAULT 0;


