USE spidd;

ALTER TABLE ORGANISME ADD CONSTRAINT FK_ORGANISME_ORGANISME FOREIGN KEY (ORG_ORGA_ID) REFERENCES ORGANISME(ORGA_ID);

ALTER TABLE bareme 
ADD CONSTRAINT FK_BAREME_ORGANISME 
FOREIGN KEY (ORGA_ID)
REFERENCES organisme (ORGA_ID);

ALTER TABLE BAREME_DETAIL 
ADD CONSTRAINT FK_BAREME_DETAIL_BAREME 
FOREIGN KEY (BAR_ID)
REFERENCES BAREME (BAR_ID)
ON DELETE CASCADE;

ALTER TABLE CAT 
ADD CONSTRAINT FK_CAT_CAT_AGE_GROUP 
FOREIGN KEY (GCAT_CD)
REFERENCES CAT_AGE_GROUP (GCAT_CD);

ALTER TABLE CATEGORIE_EPREUVE 
ADD CONSTRAINT FK_CATEGORIE_EPREUVE_CAT 
FOREIGN KEY (CAT_ID)
REFERENCES CAT (CAT_ID);

ALTER TABLE CATEGORIE_EPREUVE 
ADD CONSTRAINT FK_CATEGORIE_EPREUVE_DIVISION 
FOREIGN KEY (DIV_ID)
REFERENCES DIVISION (DIV_ID);

ALTER TABLE CELLULE_POT 
ADD CONSTRAINT FK_CELLULE_POT_LIGNE_POT 
FOREIGN KEY (LIGNE_POT_ID)
REFERENCES LIGNE_POT (LIGNE_POT_ID);

ALTER TABLE CELLULE_POT 
ADD CONSTRAINT FK_CELLULE_POT_TABLEAU_PARTIE 
FOREIGN KEY (TABPART_ID_TABLEAU)
REFERENCES TABLEAU_PARTIE (TABPART_ID_TABLEAU);

ALTER TABLE CLASSEMENT 
ADD CONSTRAINT FK_CLASSEMENT_LICENCIE 
FOREIGN KEY (LIC_ID)
REFERENCES LICENCIE (LIC_ID);

ALTER TABLE CLASSEMENT 
ADD CONSTRAINT FK_CLASSEMENT_NIVEAU 
FOREIGN KEY (NIV_ID)
REFERENCES NIVEAU (NIV_ID);

ALTER TABLE CLASSEMENT 
ADD CONSTRAINT FK_CLASSEMENT_POULE 
FOREIGN KEY (POUL_ID)
REFERENCES POULE (POUL_ID);

ALTER TABLE CLASSEMENT 
ADD CONSTRAINT FK_CLASSEMENT_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);

ALTER TABLE CLUB 
ADD CONSTRAINT FK_CLUB_ORGANISME 
FOREIGN KEY (ORGA_ID)
REFERENCES ORGANISME (ORGA_ID);

ALTER TABLE DIVISION 
ADD CONSTRAINT FK_DIVISION_BAREME 
FOREIGN KEY (BAR_ID)
REFERENCES BAREME (BAR_ID);

ALTER TABLE DIVISION 
ADD CONSTRAINT FK_DIVISION_CAT_AGE_GROUP 
FOREIGN KEY (GCAT_CD)
REFERENCES CAT_AGE_GROUP (GCAT_CD);

ALTER TABLE DIVISION 
ADD CONSTRAINT FK_DIVISION_EPREUVE 
FOREIGN KEY (EPRV_ID)
REFERENCES EPREUVE (EPRV_ID);

ALTER TABLE DIVISION 
ADD CONSTRAINT FK_DIVISION_ORGANISME 
FOREIGN KEY (ORGA_ID)
REFERENCES ORGANISME (ORGA_ID);

ALTER TABLE EPREUVE 
ADD CONSTRAINT FK_EPREUVE_ORGANISME 
FOREIGN KEY (ORGA_ID)
REFERENCES ORGANISME (ORGA_ID);

ALTER TABLE GRILLE_DETAIL 
ADD CONSTRAINT FK_GRILLE_DETAIL_GRILLE_RENCONTRE 
FOREIGN KEY (GRIL_ID_RENC)
REFERENCES GRILLE_RENCONTRE (GRIL_ID_RENC);

ALTER TABLE GRILLE_RENCONTRE 
ADD CONSTRAINT FK_GRILLE_RENCONTRE_ORGANISME 
FOREIGN KEY (ORGA_ID)
REFERENCES ORGANISME (ORGA_ID);

ALTER TABLE INSCRIPTION 
ADD CONSTRAINT FK_INSCRIPTION_JOUEUR 
FOREIGN KEY (JOUE_ID)
REFERENCES JOUEUR (JOUE_ID);

ALTER TABLE INSCRIPTION 
ADD CONSTRAINT FK_INSCRIPTION_POULE 
FOREIGN KEY (POUL_ID)
REFERENCES POULE (POUL_ID);

ALTER TABLE INSCRIPTION 
ADD CONSTRAINT FK_INSCRIPTION_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);



ALTER TABLE INSCRIPTION 
ADD CONSTRAINT FK_INSCRIPTION_TOUR_PREC 
FOREIGN KEY (TOUR_ID_PREC)
REFERENCES TOUR (TOUR_ID);



ALTER TABLE JOUEUR 
ADD CONSTRAINT FK_JOUEUR_LICENCIE 
FOREIGN KEY (LIC_ID)
REFERENCES LICENCIE (LIC_ID);

ALTER TABLE LICENCIE 
ADD CONSTRAINT FK_LICENCIE_CAT 
FOREIGN KEY (CAT_ID)
REFERENCES CAT (CAT_ID);



ALTER TABLE LICENCIE 
ADD CONSTRAINT FK_LICENCIE_CLUB 
FOREIGN KEY (CLUB_ID)
REFERENCES CLUB (CLUB_ID);

ALTER TABLE LICENCIE 
ADD CONSTRAINT FK_LICENCIE_CLUB_CLUBID 
FOREIGN KEY (CLU_CLUB_ID)
REFERENCES CLUB (CLUB_ID);

ALTER TABLE LICENCIE 
ADD CONSTRAINT FK_LICENCIE_TYPE_CLASSEMENT 
FOREIGN KEY (TCLST_ID)
REFERENCES TYPE_CLASSEMENT (TCLST_ID);

ALTER TABLE LIGNE_POT 
ADD CONSTRAINT FK_LIGNE_POT_POT 
FOREIGN KEY (POT_ID)
REFERENCES POT (POT_ID);

ALTER TABLE MANCHE 
ADD CONSTRAINT FK_MANCHE_TABLEAU_PARTIE 
FOREIGN KEY (TABPART_ID_TABLEAU)
REFERENCES TABLEAU_PARTIE (TABPART_ID_TABLEAU);

USE spidd;
ALTER TABLE NIVEAU 
ADD CONSTRAINT FK_NIVEAU_NIVEAU_REF 
FOREIGN KEY (NIVREF_ID)
REFERENCES NIVEAU_REF (NIVREF_ID);

USE spidd;
ALTER TABLE NIVEAU 
ADD CONSTRAINT FK_NIVEAU_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);

USE spidd;
ALTER TABLE NIVEAU_REF 
ADD CONSTRAINT FK_NIVEAU_REF_NIVEAU_REF 
FOREIGN KEY (NIVREF_NIVREF_ID)
REFERENCES NIVEAU_REF (NIVREF_ID);

USE spidd;
ALTER TABLE NIVEAU_REF 
ADD CONSTRAINT FK_NIVEAU_REF_TABLEAU_REF 
FOREIGN KEY (TABREF_ID)
REFERENCES TABLEAU_REF (TABREF_ID);

USE spidd;
ALTER TABLE PACKAGE_TABLEAU 
ADD CONSTRAINT FK_PACKAGE_TABLEAU_PACKAGE 
FOREIGN KEY (PKG_ID)
REFERENCES PACKAGE (PKG_ID);

ALTER TABLE PACKAGE_TABLEAU 
ADD CONSTRAINT FK_PACKAGE_TABLEAU_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);

ALTER TABLE PARTIE 
ADD CONSTRAINT FK_PARTIE_EPREUVE 
FOREIGN KEY (EPRV_ID)
REFERENCES EPREUVE (EPRV_ID);

ALTER TABLE PARTIE 
ADD CONSTRAINT FK_PARTIE_LICENCIE1 
FOREIGN KEY (LIC_ID)
REFERENCES LICENCIE (LIC_ID);

ALTER TABLE PARTIE 
ADD CONSTRAINT FK_PARTIE_LICENCIE2 
FOREIGN KEY (LIC_LIC_ID)
REFERENCES LICENCIE (LIC_ID);

ALTER TABLE PARTIE 
ADD CONSTRAINT FK_PARTIE_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);



ALTER TABLE PARTIE_REF 
ADD CONSTRAINT FK_PARTIE_REF_NIVEAU_REF 
FOREIGN KEY (NIVREF_ID)
REFERENCES NIVEAU_REF (NIVREF_ID);

ALTER TABLE PARTIE_REF 
ADD CONSTRAINT FK_PARTIE_REF_PARTIE_REF1 
FOREIGN KEY (PAR_RPARTI_ID_PARTIE_REF)
REFERENCES PARTIE_REF (RPARTI_ID_PARTIE_REF);

ALTER TABLE PARTIE_REF 
ADD CONSTRAINT FK_PARTIE_REF_PARTIE_REF2 
FOREIGN KEY (PAR2_RPARTI_ID_PARTIE_REF)
REFERENCES PARTIE_REF (RPARTI_ID_PARTIE_REF);

ALTER TABLE POT_TABLEAU 
ADD CONSTRAINT FK_POT_TABLEAU_POT 
FOREIGN KEY (POT_ID)
REFERENCES POT (POT_ID);

ALTER TABLE POT_TABLEAU 
ADD CONSTRAINT FK_POT_TABLEAU_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);

ALTER TABLE POULE 
ADD CONSTRAINT FK_POULE_DIVISION 
FOREIGN KEY (DIV_ID)
REFERENCES DIVISION (DIV_ID);

ALTER TABLE POULE 
ADD CONSTRAINT FK_POULE_GRILLE_RENCONTRE 
FOREIGN KEY (GRIL_ID_RENC)
REFERENCES GRILLE_RENCONTRE (GRIL_ID_RENC);

ALTER TABLE POULE 
ADD CONSTRAINT FK_POULE_TABLEAU 
FOREIGN KEY (TAB_ID)
REFERENCES TABLEAU (TAB_ID);

ALTER TABLE TABLEAU 
ADD CONSTRAINT FK_TABLEAU_TABLEAU_REF 
FOREIGN KEY (TABREF_ID)
REFERENCES TABLEAU_REF (TABREF_ID);

ALTER TABLE TABLEAU 
ADD CONSTRAINT FK_TABLEAU_TOUR 
FOREIGN KEY (TOUR_ID)
REFERENCES TOUR (TOUR_ID);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_INSCRIPTION 
FOREIGN KEY (INSC_ID)
REFERENCES INSCRIPTION (INSC_ID);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_INSCRIPTION1 
FOREIGN KEY (INS_INSC_ID)
REFERENCES INSCRIPTION (INSC_ID);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_NIVEAU 
FOREIGN KEY (NIV_ID)
REFERENCES NIVEAU (NIV_ID);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_PARTIE 
FOREIGN KEY (PARTI_ID)
REFERENCES PARTIE (PARTI_ID);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_PARTIE_REF 
FOREIGN KEY (RPARTI_ID_PARTIE_REF)
REFERENCES PARTIE_REF (RPARTI_ID_PARTIE_REF);

ALTER TABLE TABLEAU_PARTIE 
ADD CONSTRAINT FK_TABLEAU_PARTIE_POULE 
FOREIGN KEY (POUL_ID)
REFERENCES POULE (POUL_ID);


ALTER TABLE TOUR 
ADD CONSTRAINT FK_TOUR_DIVISION 
FOREIGN KEY (DIV_ID)
REFERENCES DIVISION (DIV_ID);

ALTER TABLE TOUR 
ADD CONSTRAINT FK_TOUR_GRILLE_RENCONTRE 
FOREIGN KEY (GRIL_ID_RENC)
REFERENCES GRILLE_RENCONTRE (GRIL_ID_RENC);





ALTER TABLE INSCRIPTION 
ADD CONSTRAINT FK_INSCRIPTION_TOUR 
FOREIGN KEY (TOUR_ID)
REFERENCES TOUR (TOUR_ID);

ALTER TABLE JOUEUR 
ADD CONSTRAINT FK_JOUEUR_EPREUVE 
FOREIGN KEY (EPRV_ID)
REFERENCES EPREUVE (EPRV_ID);

ALTER TABLE LICENCIE 
ADD CONSTRAINT FK_LICENCIE_CAT_SPORT 
FOREIGN KEY (CAT_SPORT_ID)
REFERENCES CAT_SPORT (CAT_SPORT_ID);

