CREATE TABLE INDIVIDU
(
IdIndividu INT NOT NULL,
CIN VARCHAR(15) NOT NULL,
Nom VARCHAR(64) NOT NULL,
Prenom VARCHAR(64) NOT NULL,
AdrCourriel VARCHAR(64) NOT NULL,
Tel VARCHAR(24) NOT NULL,
CONSTRAINT INDIVIDU_PK PRIMARY KEY (IdIndividu),
CONSTRAINT INDIVIDU_AK UNIQUE (CIN)
) ;
CREATE TABLE CLIENT
(
IdClient INT NOT NULL,
AdresseClient VARCHAR(64) NOT NULL,
CONSTRAINT CLIENT_PK PRIMARY KEY (IdClient),
CONSTRAINT CLIENT_INDIVIDU_FK FOREIGN KEY (IdClient)
REFERENCES INDIVIDU (IdIndividu) ON DELETE CASCADE
) ;
CREATE TABLE PROJET
(
IdProjet INT NOT NULL,
ClientId INT NOT NULL,
CodeProjet CHAR(5) NOT NULL,
NomProjet VARCHAR(64) NOT NULL,
DescriptionProjet VARCHAR(64) NOT NULL,
DateDebut DATE NOT NULL,
DateFin DATE NOT NULL,
EtatProjet CHAR(5) NOT NULL,
IdProjetParent INT ,
CONSTRAINT PROJET_PK PRIMARY KEY (IdProjet),
CONSTRAINT PROJET_AK UNIQUE (CodeProjet),
CONSTRAINT PROJET_CLIENT_FK FOREIGN KEY (ClientId)
REFERENCES CLIENT (IdClient),
CONSTRAINT PROJET_PROJET_FK FOREIGN KEY (IdProjetParent)
REFERENCES PROJET (IdProjet)
) ;
CREATE TABLE CAHIER_CHARGES
(
IdProjet INT NOT NULL,
CodeCahier VARCHAR(48) NOT NULL,
DetailCahier VARCHAR(48) NOT NULL,
CONSTRAINT CAHIER_CHARGES_PK PRIMARY KEY (IdProjet),
CONSTRAINT CAHIER_CHARGES_AK UNIQUE (CodeCahier),
CONSTRAINT CAHIER_CHARGES_PROJET_FK FOREIGN KEY (IdProjet)
REFERENCES PROJET (IdProjet) ON DELETE CASCADE
) ;
CREATE TABLE DEVIS
(
IdProjet INT NOT NULL,
CodeDevis CHAR(5) NOT NULL,
LibelleDevis VARCHAR(64) NOT NULL,
MontantDevis DECIMAL(7,2) NOT NULL,
CONSTRAINT DEVIS_PK PRIMARY KEY (IdProjet),
CONSTRAINT DEVIS_PROJET_FK FOREIGN KEY (IdProjet)
REFERENCES PROJET (IdProjet) ON DELETE CASCADE
) ;
CREATE TABLE PERSONNEL
(
IdPersonnel INT NOT NULL,
Role VARCHAR(64) NOT NULL,
CONSTRAINT PERSONNEL_PK PRIMARY KEY (IdPersonnel),
CONSTRAINT PERSONNEL_INDIVIDU_FK FOREIGN KEY (IdPersonnel)
REFERENCES INDIVIDU (IdIndividu) ON DELETE CASCADE
) ;
CREATE TABLE NOTIFICATION
(
IdExpediteur INT NOT NULL,
IdDestinataire INT NOT NULL,
Titre VARCHAR(64) NOT NULL,
Commentaires VARCHAR(64) NOT NULL,
CONSTRAINT NOTIFICATION_PK PRIMARY KEY (IdExpediteur, IdDestinataire),
CONSTRAINT PERSONNEL_NOTIF_DEST_FK FOREIGN KEY (IdDestinataire)
REFERENCES PERSONNEL (IdPersonnel),
CONSTRAINT PERSONNEL_NOTIF_EXP_FK FOREIGN KEY (IdExpediteur)
REFERENCES PERSONNEL (IdPersonnel)
) ;
CREATE TABLE MATERIEL
(
IdMateriel INT NOT NULL,
CodeMateriel CHAR(5) NOT NULL,
LibelleMateriel VARCHAR(64) NOT NULL,
IdTypeMateriel INT NOT NULL,
CONSTRAINT MATERIEL_PK PRIMARY KEY (IdMateriel),
CONSTRAINT MATERIEL_AK UNIQUE (CodeMateriel)
) ;
CREATE TABLE PROJET_MATERIEL
(
IdProjet INT NOT NULL,
IdMateriel INT NOT NULL,
CONSTRAINT PROJET_MATERIEL_PK PRIMARY KEY (IdProjet, IdMateriel),
CONSTRAINT PROJET_MATERIEL_PROJET_FK FOREIGN KEY (IdProjet)
REFERENCES PROJET (IdProjet) ON DELETE CASCADE,
CONSTRAINT PROJET_MATERIEL_MATERIEL_FK FOREIGN KEY (IdMateriel)
REFERENCES MATERIEL (IdMateriel)
) ;
Partager