diff --git a/BDD/Cours/Amphi/05.09.22/Intro-BD-1A.pdf b/BDD/Cours/Amphi/05.09.22/Intro-BD-1A.pdf new file mode 100644 index 0000000..3acd61d Binary files /dev/null and b/BDD/Cours/Amphi/05.09.22/Intro-BD-1A.pdf differ diff --git a/BDD/Cours/Amphi/05.09.22/VideoCours.url b/BDD/Cours/Amphi/05.09.22/VideoCours.url new file mode 100644 index 0000000..4676387 --- /dev/null +++ b/BDD/Cours/Amphi/05.09.22/VideoCours.url @@ -0,0 +1,6 @@ +[InternetShortcut] +URL=https://ucafr-my.sharepoint.com/:v:/r/personal/pascal_lafourcade_uca_fr/Documents/Enregistrements/CM%20BD%201A-20220905_134114-Enregistrement%20de%20la%20r%C3%A9union.mp4?csf=1&web=1&e=86k1C0 +IDList= +HotKey=0 +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,11 diff --git a/BDD/Cours/DocSSH.url b/BDD/Cours/DocSSH.url new file mode 100644 index 0000000..83cd96c --- /dev/null +++ b/BDD/Cours/DocSSH.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://s2i.iut.uca.fr/page/documentation/sgbd/ diff --git a/BDD/Cours/TD/polyBD.pdf b/BDD/Cours/TD/polyBD.pdf new file mode 100644 index 0000000..f7dae77 Binary files /dev/null and b/BDD/Cours/TD/polyBD.pdf differ diff --git a/BDD/SAE/SAE_BDD.pdf b/BDD/SAE/SAE_BDD.pdf new file mode 100644 index 0000000..62cc7b8 Binary files /dev/null and b/BDD/SAE/SAE_BDD.pdf differ diff --git a/BDD/tp/tp1_2/tp1_2.sql b/BDD/tp/tp1_2/tp1_2.sql new file mode 100644 index 0000000..afc481c --- /dev/null +++ b/BDD/tp/tp1_2/tp1_2.sql @@ -0,0 +1,49 @@ +DROP TABLE IF EXISTS TERRITOIRE, DRAGON, NOURRITURE, REPAS, AMOUR; +CREATE TABLE TERRITOIRE( + num_terr char(3) PRIMARY KEY, + nom char(20), + longitude numeric, + latitude1 numeric, + latitude2 char(2) +); +CREATE TABLE DRAGON( + num char(5) PRIMARY KEY, + nom char(30), + longueur numeric, + sexe numeric, + nb_ecailles numeric, + date_naissance date, + en_amour char(20), + crache_feu char(1), + num_terr char(4) REFERENCES TERRITOIRE +); +CREATE TABLE NOURRITURE( + num char(3) PRIMARY KEY, + nom varchar(20), + calories numeric +); +CREATE TABLE AMOUR( + force varchar(20), + num_dragon1 char(5), + num_dragon2 char(5), + PRIMARY KEY (num_dragon1, num_dragon2), + FOREIGN KEY (num_dragon1) REFERENCES DRAGON(num), + FOREIGN KEY (num_dragon2) REFERENCES DRAGON(num) +); +CREATE TABLE REPAS( + qte numeric, + date_repas date, + num_nourr char(5), + num_dragon char(5), + PRIMARY KEY (num_nourr, num_dragon), + FOREIGN KEY (num_nourr) REFERENCES NOURRITURE(num), + FOREIGN KEY (num_dragon) REFERENCES DRAGON(num) +); + +\d + +/*SELECT * FROM TERRITOIRE; +SELECT * FROM DRAGON; +SELECT * FROM NOURRITURE; +SELECT * FROM AMOUR; +SELECT * FROM REPAS;*/ \ No newline at end of file diff --git a/BDD/tp/tp3/tp3.sql b/BDD/tp/tp3/tp3.sql new file mode 100644 index 0000000..3931214 --- /dev/null +++ b/BDD/tp/tp3/tp3.sql @@ -0,0 +1,121 @@ +DROP TABLE IF EXISTS REPAS; +DROP TABLE IF EXISTS NOURRITURE; +DROP TABLE IF EXISTS AMOUR; +DROP TABLE IF EXISTS DRAGON; +DROP TABLE IF EXISTS TERRITOIRE; + +\! clear + +CREATE TABLE TERRITOIRE( + num_terr char(3) NOT NULL PRIMARY KEY, + nom varchar(30) UNIQUE, + longitude numeric NOT NULL CHECK(longitude <= 180 AND longitude >= -180), + latitude1 numeric NOT NULL CHECK (latitude1 <= 90), + latitude2 char(1) NOT NULL CHECK (latitude2 = 'N' OR latitude2 = 'S') +); +CREATE TABLE DRAGON( + num char(5) NOT NULL PRIMARY KEY, + nom varchar(30) UNIQUE, + longueur numeric NOT NULL CHECK (longueur > 0), + sexe char(1) NOT NULL CHECK (sexe = 'F' OR sexe = 'M'), + nb_ecailles numeric NOT NULL CHECK (nb_ecailles >= 0), + date_naissance date NOT NULL, + en_amour varchar(20) CHECK (en_amour = 'macho' OR en_amour = 'timide' OR en_amour = 'sincere' OR en_amour = 'volage'), + crache_feu char(1) CHECK (crache_feu = 'O' OR crache_feu = 'N'), + num_terr char(4) REFERENCES TERRITOIRE, + CHECK (sexe = 1 AND en_amour = 'macho' OR sexe = 0 AND en_amour != 'macho') +); +CREATE TABLE NOURRITURE( + num char(5) PRIMARY KEY, + nom varchar(30) NOT NULL UNIQUE, + calories numeric NOT NULL CHECK(calories > 0) +); +CREATE TABLE AMOUR( + force varchar(20) CHECK (force = 'un peu' OR force = 'beaucoup' OR force = 'pasionnement' OR force = 'a la folie'), + num_dragon1 char(5) REFERENCES DRAGON, + num_dragon2 char(5) REFERENCES DRAGON, + PRIMARY KEY (num_dragon1, num_dragon2) +); +CREATE TABLE REPAS( + qte numeric CHECK(qte > 0), + date_repas date, + num_dragon char(5) REFERENCES DRAGON, + num_nourr char(5) REFERENCES NOURRITURE, + PRIMARY KEY (num_dragon, num_nourr) +); +/* +INSERT INTO TERRITOIRE VALUES('T01', 'terre brûlées', 92, 40, 'S'); + + +INSERT INTO DRAGON VALUES('d0001', 'Solong', '173', 'M', '1481', '25/02/2012', 'timide', 'O', 't01'); + +INSERT INTO NOURRITURE VALUES('P0001','pomme',7); + +INSERT INTO AMOUR VALUES(NULL, 'D0001', 'D0002'); + +INSERT INTO REPAS VALUES(1000,'10/09/2021','D0001','P0002'); + +INSERT INTO + + +TRUNCATE TABLE TERRITOIRE, DRAGON, NOURRITURE, AMOUR, REPAS; +*/ +INSERT INTO DRAGON VALUES('d0001', 'Solong', '173', 'M', '1481', '25/02/2012', 'timide', 'O', 't01'); +INSERT INTO TERRITOIRE VALUES('T01', 'terre brûlées', 92, 40, 'S'); +INSERT INTO AMOUR VALUES + + +TRUNCATE TABLE TERRITOIRE, DRAGON, NOURRITURE, AMOUR, REPAS; + +INSERT INTO TERRITOIRE VALUES ('T01','terres_brulees',92,42,'S'); +INSERT INTO TERRITOIRE VALUES ('T02','terre_des_fleurs',98,48,'S'); +INSERT INTO TERRITOIRE VALUES ('T03','terre_des_neiges',100,8,'N'); + + +INSERT INTO DRAGON VALUES ('D0001','Smeagol',152,1,1857,'14/06/1985','macho','O','T01'); +INSERT INTO DRAGON VALUES ('D0002','Birdurh',258,1,4787,'05/05/1989','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0003','Negueth',128,1,1587,'08/09/2018','sincere','O','T02'); +INSERT INTO DRAGON VALUES ('D0004','Miss Toc',183,1,2781,'04/07/2020','volage',NULL,'T01'); +INSERT INTO DRAGON VALUES ('D0005','Bolong',213,1,754,'06/05/2010','macho','N','T01'); +INSERT INTO DRAGON VALUES ('D0006','Miloch',83,1,718,'29/04/2015','timide','O','T02'); +INSERT INTO DRAGON VALUES ('D0007','Nessie',168,1,1721,'12/12/2000','macho','O','T02'); +INSERT INTO DRAGON VALUES ('D0008','Tarak',123,0,851,'15/04/2009','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0009','Solong',173,1,1481,'04/08/2021','timide',NULL,'T01'); + + +INSERT INTO NOURRITURE VALUES ('P0001','pomme',7); +INSERT INTO NOURRITURE VALUES ('P0002','cacahuete',10); +INSERT INTO NOURRITURE VALUES ('P0003','orange',25); +INSERT INTO NOURRITURE VALUES ('P0004','oeuf',15); +INSERT INTO NOURRITURE VALUES ('P0005','ver',3); +INSERT INTO NOURRITURE VALUES ('P0006','poisson',35); + +INSERT INTO AMOUR VALUES ('passionnement','D0001','D0008'); +INSERT INTO AMOUR VALUES ('beaucoup','D0002','D0003'); +INSERT INTO AMOUR VALUES ('a la folie','D0003','D0006'); +INSERT INTO AMOUR VALUES ('a la folie','D0006','D0003'); +INSERT INTO AMOUR VALUES ('un peu','D0008','D0005'); +INSERT INTO AMOUR VALUES ('beaucoup','D0005','D0008'); +INSERT INTO AMOUR VALUES ('un peu','D0007','D0008'); + +INSERT INTO REPAS VALUES (1000,'10/09/2021','D0001','P0002'); +INSERT INTO REPAS VALUES (16,'10/09/2021','D0001','P0001'); +INSERT INTO REPAS VALUES (4,'11/09/2021','D0005','P0004'); +INSERT INTO REPAS VALUES (6,'10/03/2021','D0003','P0003'); +INSERT INTO REPAS VALUES (1,'11/09/2021','D0003','P0004'); +INSERT INTO REPAS VALUES (53,'10/09/2021','D0006','P0005'); +INSERT INTO REPAS VALUES (100,'11/09/2021','D0006','P0002'); +INSERT INTO REPAS VALUES (20,'10/09/2021','D0007','P0006'); +INSERT INTO REPAS VALUES (10,'10/09/2021','D0008','P0001'); +INSERT INTO REPAS VALUES (10,'11/09/2021','D0008','P0003'); +INSERT INTO REPAS VALUES (6,'09/09/2021','D0009','P0004'); +INSERT INTO REPAS VALUES (1,'10/09/2021','D0009','P0006'); +INSERT INTO REPAS VALUES (2,'11/09/2021','D0009','P0003'); + +SELECT * FROM TERRITOIRE; +SELECT * FROM DRAGON; +SELECT * FROM NOURRITURE; +SELECT * FROM AMOUR; +SELECT * FROM REPAS; + +\d \ No newline at end of file diff --git a/BDD/tp/tp3/tp3f.sql b/BDD/tp/tp3/tp3f.sql new file mode 100644 index 0000000..b0e70e4 --- /dev/null +++ b/BDD/tp/tp3/tp3f.sql @@ -0,0 +1,102 @@ +DROP TABLE REPAS; +DROP TABLE AMOUR; +DROP TABLE DRAGON; +DROP TABLE NOURRITURE; +DROP TABLE TERRITOIRE; + +\! clear + +CREATE TABLE TERRITOIRE( + num_terr char(3) PRIMARY KEY, + nom varchar(30) UNIQUE, + longitude numeric NOT NULL CHECK (longitude <= 180 AND longitude >= -180), + latitude1 numeric NOT NULL CHECK (latitude1 <= 90), + latitude2 char(1) NOT NULL CHECK (latitude2 ='S' OR latitude2 ='N') +); +CREATE TABLE DRAGON( + numD char(5) PRIMARY KEY, + nom varchar(30) UNIQUE, + longeur numeric NOT NULL CHECK (longeur > 0), + sexe char(1) NOT NULL CHECK (sexe ='F' OR sexe ='M'), + nb_ecailles numeric CHECK (nb_ecailles > 0), + date_naissance date, + en_amour varchar(20) NOT NULL CHECK (en_amour ='macho' AND sexe='M' OR en_amour='timide' OR en_amour='sincere' OR en_amour='volage'), + crache_feu char(1) CHECK (crache_feu ='O' OR crache_feu ='N'), + num_terr char(4) REFERENCES TERRITOIRE + +); + +CREATE TABLE NOURRITURE( + numN char(5)PRIMARY KEY, + nom varchar(30) UNIQUE, + calories numeric NOT NULL CHECK (calories >0) + +); +CREATE TABLE AMOUR ( + force varchar(20) CHECK (force='un peu' OR force='beaucoup' OR force='passionnement' OR force='a la folie'), + numDragon1 char(5) REFERENCES DRAGON, + numDragon2 char(5) REFERENCES DRAGON, + PRIMARY KEY (numDragon1,numDragon2) + + +); + +CREATE TABLE REPAS( + qte numeric NOT NULL CHECK (qte >0), + date_repas date, + numD char(5) REFERENCES DRAGON, + numN char(5) REFERENCES NOURRITURE, + PRIMARY KEY (numD,numN) +); + +INSERT INTO TERRITOIRE VALUES ('T01','terres_brulees',92,42,'S'); +INSERT INTO TERRITOIRE VALUES ('T02','terre_des_fleurs',98,48,'S'); +INSERT INTO TERRITOIRE VALUES ('T03','terre_des_neiges',100,8,'N'); + + +INSERT INTO DRAGON VALUES ('D0001','Smeagol',152,'M',1857,'14/06/1985','macho','O','T02'); +INSERT INTO DRAGON VALUES ('D0002','Birdurh',258,'M',4787,'05/05/1989','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0003','Negueth',128,'M',1587,'08/09/2018','sincere','O','T02'); +INSERT INTO DRAGON VALUES ('D0004','Miss Toc',183,'M',2781,'04/07/2020','volage',NULL,'T01'); +INSERT INTO DRAGON VALUES ('D0005','Bolong',213,'M',754,'06/05/2010','macho','N','T01'); +INSERT INTO DRAGON VALUES ('D0006','Miloch',83,'M',718,'29/04/2015','timide','O','T02'); +INSERT INTO DRAGON VALUES ('D0007','Nessie',168,'M',1721,'12/12/2000','macho','O','T02'); +INSERT INTO DRAGON VALUES ('D0008','Tarak',123,'F',851,'15/04/2009','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0009','Solong',173,'M',1481,'04/08/2021','timide',NULL,'T01'); + + +INSERT INTO NOURRITURE VALUES ('P0001','pomme',7); +INSERT INTO NOURRITURE VALUES ('P0002','cacahuete',10); +INSERT INTO NOURRITURE VALUES ('P0003','orange',25); +INSERT INTO NOURRITURE VALUES ('P0004','oeuf',15); +INSERT INTO NOURRITURE VALUES ('P0005','ver',3); +INSERT INTO NOURRITURE VALUES ('P0006','poisson',35); + +INSERT INTO AMOUR VALUES ('passionnement','D0001','D0008'); +INSERT INTO AMOUR VALUES ('beaucoup','D0002','D0003'); +INSERT INTO AMOUR VALUES ('a la folie','D0003','D0006'); +INSERT INTO AMOUR VALUES ('a la folie','D0006','D0003'); +INSERT INTO AMOUR VALUES ('un peu','D0008','D0005'); +INSERT INTO AMOUR VALUES ('beaucoup','D0005','D0008'); +INSERT INTO AMOUR VALUES ('un peu','D0007','D0008'); + +INSERT INTO REPAS VALUES (1000,'10/09/2021','D0001','P0002'); +INSERT INTO REPAS VALUES (16,'10/09/2021','D0001','P0001'); +INSERT INTO REPAS VALUES (4,'11/09/2021','D0005','P0004'); +INSERT INTO REPAS VALUES (6,'10/03/2021','D0003','P0003'); +INSERT INTO REPAS VALUES (1,'11/09/2021','D0003','P0004'); +INSERT INTO REPAS VALUES (53,'10/09/2021','D0006','P0005'); +INSERT INTO REPAS VALUES (100,'11/09/2021','D0006','P0002'); +INSERT INTO REPAS VALUES (20,'10/09/2021','D0007','P0006'); +INSERT INTO REPAS VALUES (10,'10/09/2021','D0008','P0001'); +INSERT INTO REPAS VALUES (10,'11/09/2021','D0008','P0003'); +INSERT INTO REPAS VALUES (6,'09/09/2021','D0009','P0004'); +INSERT INTO REPAS VALUES (1,'10/09/2021','D0009','P0006'); +INSERT INTO REPAS VALUES (2,'11/09/2021','D0009','P0003'); + +SELECT * FROM TERRITOIRE; +SELECT * FROM DRAGON; +SELECT * FROM NOURRITURE; +SELECT * FROM AMOUR; +SELECT * FROM REPAS; +\d \ No newline at end of file diff --git a/BDD/tp/tp4/tp4.sql b/BDD/tp/tp4/tp4.sql new file mode 100644 index 0000000..863362f --- /dev/null +++ b/BDD/tp/tp4/tp4.sql @@ -0,0 +1,120 @@ +DROP TABLE REPAS; +DROP TABLE AMOUR; +DROP TABLE DRAGON; +DROP TABLE NOURRITURE; +DROP TABLE TERRITOIRE; + +\! clear + +CREATE TABLE TERRITOIRE( + num_terr char(3) PRIMARY KEY, + nom varchar(30) UNIQUE, + longitude numeric NOT NULL CHECK (longitude <= 180 AND longitude >= -180), + latitude1 numeric NOT NULL CHECK (latitude1 <= 90), + latitude2 char(1) NOT NULL CHECK (latitude2 ='S' OR latitude2 ='N') +); +CREATE TABLE DRAGON( + numD char(5) PRIMARY KEY, + nom varchar(30) UNIQUE, + longeur numeric NOT NULL CHECK (longeur > 0), + sexe char(1) NOT NULL CHECK (sexe ='F' OR sexe ='M'), + nb_ecailles numeric CHECK (nb_ecailles > 0), + date_naissance date, + en_amour varchar(20) NOT NULL CHECK (en_amour ='macho' AND sexe='M' OR en_amour='timide' OR en_amour='sincere' OR en_amour='volage'), + crache_feu char(1) CHECK (crache_feu ='O' OR crache_feu ='N'), + num_terr char(4) REFERENCES TERRITOIRE + +); + +CREATE TABLE NOURRITURE( + numN char(5)PRIMARY KEY, + nom varchar(30) UNIQUE, + calories numeric NOT NULL CHECK (calories >0) + +); +CREATE TABLE AMOUR ( + force varchar(20) CHECK (force='un peu' OR force='beaucoup' OR force='passionnement' OR force='a la folie'), + numDragon1 char(5) REFERENCES DRAGON, + numDragon2 char(5) REFERENCES DRAGON, + PRIMARY KEY (numDragon1,numDragon2) + + +); + +CREATE TABLE REPAS( + qte numeric NOT NULL CHECK (qte >0), + date_repas date, + numD char(5) REFERENCES DRAGON, + numN char(5) REFERENCES NOURRITURE, + PRIMARY KEY (numD,numN) +); + +INSERT INTO TERRITOIRE VALUES('T01', 'terre brûlées', 92, 40, 'S'); + +INSERT INTO DRAGON VALUES('D0001', 'Solong', 173, 'M', 1481, '25/02/2012', 'timide', 'O', 'T01'); +INSERT INTO DRAGON VALUES('D0002', 'Tarak', 123, 'F', 851, '20/05/2015', 'timide', 'O', 'T01'); +INSERT INTO DRAGON VALUES('D0003', 'Birdurh', 258, 'M', 4787, '08/09/2018', 'timide', 'O', 'T01'); + +UPDATE DRAGON +SET en_amour = CASE crache_feu +WHEN 'O' THEN 'volage' + +INSERT INTO NOURRITURE VALUES('P0002','pomme',7); + +INSERT INTO AMOUR VALUES('un peu', 'D0001', 'D0002'); + +INSERT INTO REPAS VALUES(1000,'10/09/2021','D0001','P0002'); +/* +INSERT INTO TERRITOIRE VALUES ('T01','terres_brulees',92,42,'S'); +INSERT INTO TERRITOIRE VALUES ('T02','terre_des_fleurs',98,48,'S'); +INSERT INTO TERRITOIRE VALUES ('T03','terre_des_neiges',100,8,'N'); + + +INSERT INTO DRAGON VALUES ('D0001','Smeagol',152,'M',1857,'14/06/1985','macho','O','T02'); +INSERT INTO DRAGON VALUES ('D0002','Birdurh',258,'M',4787,'05/05/1989','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0003','Negueth',128,'M',1587,'08/09/2018','sincere','O','T02'); +INSERT INTO DRAGON VALUES ('D0004','Miss Toc',183,'M',2781,'04/07/2020','volage',NULL,'T01'); +INSERT INTO DRAGON VALUES ('D0005','Bolong',213,'M',754,'06/05/2010','macho','N','T01'); +INSERT INTO DRAGON VALUES ('D0006','Miloch',83,'M',718,'29/04/2015','timide','O','T02'); +INSERT INTO DRAGON VALUES ('D0007','Nessie',168,'M',1721,'12/12/2000','macho','O','T02'); +INSERT INTO DRAGON VALUES ('D0008','Tarak',123,'F',851,'15/04/2009','timide','N','T01'); +INSERT INTO DRAGON VALUES ('D0009','Solong',173,'M',1481,'04/08/2021','timide',NULL,'T01'); + + +INSERT INTO NOURRITURE VALUES ('P0001','pomme',7); +INSERT INTO NOURRITURE VALUES ('P0002','cacahuete',10); +INSERT INTO NOURRITURE VALUES ('P0003','orange',25); +INSERT INTO NOURRITURE VALUES ('P0004','oeuf',15); +INSERT INTO NOURRITURE VALUES ('P0005','ver',3); +INSERT INTO NOURRITURE VALUES ('P0006','poisson',35); + +INSERT INTO AMOUR VALUES ('passionnement','D0001','D0008'); +INSERT INTO AMOUR VALUES ('beaucoup','D0002','D0003'); +INSERT INTO AMOUR VALUES ('a la folie','D0003','D0006'); +INSERT INTO AMOUR VALUES ('a la folie','D0006','D0003'); +INSERT INTO AMOUR VALUES ('un peu','D0008','D0005'); +INSERT INTO AMOUR VALUES ('beaucoup','D0005','D0008'); +INSERT INTO AMOUR VALUES ('un peu','D0007','D0008'); + +INSERT INTO REPAS VALUES (1000,'10/09/2021','D0001','P0002'); +INSERT INTO REPAS VALUES (16,'10/09/2021','D0001','P0001'); +INSERT INTO REPAS VALUES (4,'11/09/2021','D0005','P0004'); +INSERT INTO REPAS VALUES (6,'10/03/2021','D0003','P0003'); +INSERT INTO REPAS VALUES (1,'11/09/2021','D0003','P0004'); +INSERT INTO REPAS VALUES (53,'10/09/2021','D0006','P0005'); +INSERT INTO REPAS VALUES (100,'11/09/2021','D0006','P0002'); +INSERT INTO REPAS VALUES (20,'10/09/2021','D0007','P0006'); +INSERT INTO REPAS VALUES (10,'10/09/2021','D0008','P0001'); +INSERT INTO REPAS VALUES (10,'11/09/2021','D0008','P0003'); +INSERT INTO REPAS VALUES (6,'09/09/2021','D0009','P0004'); +INSERT INTO REPAS VALUES (1,'10/09/2021','D0009','P0006'); +INSERT INTO REPAS VALUES (2,'11/09/2021','D0009','P0003'); +*/ + +SELECT * FROM TERRITOIRE; +SELECT * FROM DRAGON; +SELECT * FROM NOURRITURE; +SELECT * FROM AMOUR; +SELECT * FROM REPAS; + +\d \ No newline at end of file diff --git a/BDD/tp/tp5/tp5.sql b/BDD/tp/tp5/tp5.sql new file mode 100644 index 0000000..e69de29