---
# System prepended metadata

title: L2BD_S4 TD5 29-03-2021

---

# L2BD_S4 TD5 29-03-2021

```sql=

Create Table personne (pid int, prenom varchar(30), nom varchar(30) ) ;

INSERT INTO personne VALUES(2330, 'Woody', 'Allen') ; INSERT INTO personne
VALUES(1281, 'Robert', 'Redford') ; INSERT INTO personne VALUES(6572, 'Robert', 'De Niro') ;


-- attention aux codage des apostrophes !!!
--INSERT INTO personne VALUES(2330, ’Woody’, ’Allen’) ; INSERT INTO personne
--VALUES(1281, ’Robert’, ’Redford’) ; INSERT INTO personne VALUES(6572, ’Robert’, ’De Niro’) ;

UPDATE Personne SET Prenom=’Paul’ WHERE pid=2330 ;

ALTER TABLE personne ADD PRIMARY KEY (pid) ;

ALTER TABLE personne ALTER pid SET NOT NULL ;

DROP TABLE personne;

CREATE TABLE personne (pid INTEGER PRIMARY KEY, prenom VARCHAR(30), nom VARCHAR(30));
CREATE TABLE Film (fid INTEGER PRIMARY KEY, titre VARCHAR(90) NOT NULL, An INTEGER NOT NULL, duree INTEGER NOT NULL, rang INTEGER NOT NULL);
CREATE TABLE Role1 (fid INTEGER REFERENCES film, pid INTEGER REFERENCES personne, nom VARCHAR(70));
CREATE TABLE MES (fid INTEGER REFERENCES film, pid INTEGER REFERENCES personne,  CONSTRAINT dir_const2 UNIQUE(fid,pid));

ALTER TABLE Film ADD CHECK (An <= 2021) ;



-- ================================

-- PsdtFestival(IdFest, NomF, Annee, Psdt)
-- Presente( IdFest, Fid)
-- PrixDecerne( IdFest, Prix, Fid, Laureat)


Create Table PsdtFestival (IdFest int PRIMARY KEY,NomF varchar(40),Annee int,Psdt int REFERENCES personne ) ;


Create Table Presente (IdFest int,Foreign Key (IdFest) REFERENCES PsdtFestival (IdFest),Fid int, Foreign Key (fid) REFERENCES film (fid) ) ;


Create Table PrixDecerne (IdFest int REFERENCES PsdtFestival, Prix varchar(40) not null,fid int REFERENCES Film,
Laureat int REFERENCES personne,Primary Key (IdFest, Prix) ) ;


ALTER TABLE PsdtFestival ADD CHECK (Psdt = 2330 OR Psdt = 1281 OR Psdt = 6572);




```