diff --git a/BE_SGBD_LIBRARY.ddl b/BE_SGBD_LIBRARY.ddl new file mode 100644 index 0000000000000000000000000000000000000000..a4c170ba0f0a8c1f5a99585618ce857a7ff1b476 --- /dev/null +++ b/BE_SGBD_LIBRARY.ddl @@ -0,0 +1,333 @@ +-- ********************************************* +-- * Standard SQL generation +-- *-------------------------------------------- +-- * DB-MAIN version: 11.0.2 +-- * Generator date: Sep 14 2021 +-- * Generation date: Wed Oct 25 17:06:28 2023 +-- * LUN file: C:\Users\matt2\AppData\Local\Temp\MicrosoftEdgeDownloads\e467d24d-0117-4ac8-9795-e70fd25f8f04\BE SGBD LIBRARY.lun +-- * Schema: MAIN/SQL +-- ********************************************* + + +-- Database Section +-- ________________ + +create database MAIN; + + +-- DBSpace Section +-- _______________ + + +-- Tables Section +-- _____________ + +create table a ( + ID_PUB numeric(10) not null, + mot char(1) not null, + constraint ID_a_ID primary key (ID_PUB, mot)); + +create table ACHAT ( + ID_EXE numeric(10) not null, + date char(1) not null, + prix char(1) not null, + lieu char(1) not null, + code char(1) not null, + constraint FKprovient_d_un_ID primary key (ID_EXE)); + +create table Auteur ( + nom char(1) not null, + constraint ID_Auteur_ID primary key (nom)); + +create table autorise_l_acces ( + nom char(1) not null, + email -- Compound attribute -- not null, + constraint ID_autorise_l_acces_ID primary key (email -- Compound attribute --, nom)); + +create table DEVISE ( + code char(1) not null, + taux char(1) not null, + symbole char(1) not null, + constraint ID_DEVISE_ID primary key (code)); + +create table EXEMPLAIRE ( + ID_EXE -- Sequence attribute not implemented -- not null, + statut char(1) not null, + nom char(1) not null, + email -- Compound attribute --, + ID_PUB numeric(10) not null, + constraint ID_ID primary key (ID_EXE)); + +create table interesse_par ( + mot char(1) not null, + email -- Compound attribute -- not null, + constraint ID_interesse_par_ID primary key (mot, email -- Compound attribute --)); + +create table LABORATOIRE ( + nom char(1) not null, + constraint ID_LABORATOIRE_ID primary key (nom)); + +create table LIVRE ( + ISBN char(13) not null, + editeur char(1) not null, + edition char(1) not null, + annee_de_publication numeric(4) not null, + categorie1 char(1), + categorie2 char(1), + categorie3 char(1), + categorie4 char(1), + constraint ID_LIVRE_ID primary key (ISBN)); + +create table MOT_CLE ( + mot char(1) not null, + constraint ID_MOT_CLE_ID primary key (mot)); + +create table PERIODIQUE ( + numero char(1) not null, + editeur char(1) not null, + edition char(1) not null, + annee_de_publication char(1) not null, + constraint ID_PERIODIQUE_ID primary key (numero, editeur, edition, annee_de_publication)); + +create table propose ( + ID_PUB numeric(10) not null, + date char(1) not null, + email -- Compound attribute -- not null, + constraint FKpro_PUB_ID primary key (ID_PUB)); + +create table PUBLICATION ( + ID_PUB -- Sequence attribute not implemented -- not null, + numero char(1), + editeur char(1), + edition char(1), + annee_de_publication char(1), + id char(1), + ISBN char(13), + type char(1) not null, + constraint ID_ID primary key (ID_PUB), + constraint FKou_est_un_ID unique (numero, editeur, edition, annee_de_publication), + constraint FKou_encore_est_un_ID unique (id), + constraint FKest_un_ID unique (ISBN)); + +create table RAPPORT ( + titre char(1) not null, + id char(1) not null, + annee_de_publication char(1) not null, + constraint ID_RAPPORT_ID primary key (id)); + +create table redige_par ( + nom char(1) not null, + id char(1) not null, + constraint ID_redige_par_ID primary key (id, nom)); + +create table UTILISATEUR ( + email -- Compound attribute -- not null, + constraint ID_UTILISATEUR_ID primary key (email -- Compound attribute --)); + +create table ecrit_par ( + nom char(1) not null, + ISBN char(13) not null, + constraint ID_ecrit_par_ID primary key (nom, ISBN)); + + +-- Constraints Section +-- ___________________ + +alter table a add constraint FKa_MOT_FK + foreign key (mot) + references MOT_CLE; + +alter table a add constraint FKa_PUB + foreign key (ID_PUB) + references PUBLICATION; + +alter table ACHAT add constraint FKprix_en_FK + foreign key (code) + references DEVISE; + +alter table ACHAT add constraint FKprovient_d_un_FK + foreign key (ID_EXE) + references EXEMPLAIRE; + +alter table autorise_l_acces add constraint FKaut_UTI + foreign key (email -- Compound attribute --) + references UTILISATEUR; + +alter table autorise_l_acces add constraint FKaut_LAB_FK + foreign key (nom) + references LABORATOIRE; + +alter table EXEMPLAIRE add constraint FKpossede_FK + foreign key (nom) + references LABORATOIRE; + +alter table EXEMPLAIRE add constraint FKemprunte_FK + foreign key (email -- Compound attribute --) + references UTILISATEUR; + +alter table EXEMPLAIRE add constraint FKcomporte_FK + foreign key (ID_PUB) + references PUBLICATION; + +alter table interesse_par add constraint FKint_UTI_FK + foreign key (email -- Compound attribute --) + references UTILISATEUR; + +alter table interesse_par add constraint FKint_MOT + foreign key (mot) + references MOT_CLE; + +alter table LIVRE add constraint ID_LIVRE_CHK + check(exists(select * from PUBLICATION + where PUBLICATION.ISBN = ISBN)); + +alter table LIVRE add constraint ID_LIVRE_CHK + check(exists(select * from ecrit_par + where ecrit_par.ISBN = ISBN)); + +alter table PERIODIQUE add constraint ID_PERIODIQUE_CHK + check(exists(select * from PUBLICATION + where PUBLICATION.numero = numero and PUBLICATION.editeur = editeur and PUBLICATION.edition = edition and PUBLICATION.annee_de_publication = annee_de_publication)); + +alter table propose add constraint FKpro_UTI_FK + foreign key (email -- Compound attribute --) + references UTILISATEUR; + +alter table propose add constraint FKpro_PUB_FK + foreign key (ID_PUB) + references PUBLICATION; + +alter table PUBLICATION add constraint FKou_est_un_FK + foreign key (numero, editeur, edition, annee_de_publication) + references PERIODIQUE; + +alter table PUBLICATION add constraint FKou_est_un_CHK + check((numero is not null and editeur is not null and edition is not null and annee_de_publication is not null) + or (numero is null and editeur is null and edition is null and annee_de_publication is null)); + +alter table PUBLICATION add constraint FKou_encore_est_un_FK + foreign key (id) + references RAPPORT; + +alter table PUBLICATION add constraint FKest_un_FK + foreign key (ISBN) + references LIVRE; + +alter table RAPPORT add constraint ID_RAPPORT_CHK + check(exists(select * from PUBLICATION + where PUBLICATION.id = id)); + +alter table RAPPORT add constraint ID_RAPPORT_CHK + check(exists(select * from redige_par + where redige_par.id = id)); + +alter table redige_par add constraint FKred_RAP + foreign key (id) + references RAPPORT; + +alter table redige_par add constraint FKred_Aut_FK + foreign key (nom) + references Auteur; + +alter table ecrit_par add constraint FKecr_LIV_FK + foreign key (ISBN) + references LIVRE; + +alter table ecrit_par add constraint FKecr_Aut + foreign key (nom) + references Auteur; + + +-- Index Section +-- _____________ + +create unique index ID_a_IND + on a (ID_PUB, mot); + +create index FKa_MOT_IND + on a (mot); + +create index FKprix_en_IND + on ACHAT (code); + +create unique index FKprovient_d_un_IND + on ACHAT (ID_EXE); + +create unique index ID_Auteur_IND + on Auteur (nom); + +create unique index ID_autorise_l_acces_IND + on autorise_l_acces (email -- Compound attribute --, nom); + +create index FKaut_LAB_IND + on autorise_l_acces (nom); + +create unique index ID_DEVISE_IND + on DEVISE (code); + +create unique index ID_IND + on EXEMPLAIRE (ID_EXE); + +create index FKpossede_IND + on EXEMPLAIRE (nom); + +create index FKemprunte_IND + on EXEMPLAIRE (email -- Compound attribute --); + +create index FKcomporte_IND + on EXEMPLAIRE (ID_PUB); + +create unique index ID_interesse_par_IND + on interesse_par (mot, email -- Compound attribute --); + +create index FKint_UTI_IND + on interesse_par (email -- Compound attribute --); + +create unique index ID_LABORATOIRE_IND + on LABORATOIRE (nom); + +create unique index ID_LIVRE_IND + on LIVRE (ISBN); + +create unique index ID_MOT_CLE_IND + on MOT_CLE (mot); + +create unique index ID_PERIODIQUE_IND + on PERIODIQUE (numero, editeur, edition, annee_de_publication); + +create index FKpro_UTI_IND + on propose (email -- Compound attribute --); + +create unique index FKpro_PUB_IND + on propose (ID_PUB); + +create unique index ID_IND + on PUBLICATION (ID_PUB); + +create unique index FKou_est_un_IND + on PUBLICATION (numero, editeur, edition, annee_de_publication); + +create unique index FKou_encore_est_un_IND + on PUBLICATION (id); + +create unique index FKest_un_IND + on PUBLICATION (ISBN); + +create unique index ID_RAPPORT_IND + on RAPPORT (id); + +create unique index ID_redige_par_IND + on redige_par (id, nom); + +create index FKred_Aut_IND + on redige_par (nom); + +create unique index ID_UTILISATEUR_IND + on UTILISATEUR (email -- Compound attribute --); + +create unique index ID_ecrit_par_IND + on ecrit_par (nom, ISBN); + +create index FKecr_LIV_IND + on ecrit_par (ISBN); +