TD N1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

create table Plat (

IdPlat int,

NomPlat varchar(30),

IdtypePlat int,

primary key (IdPlat),

foreign key (IdtypePlat) references typePlat(IdtypePlat)

);

create table typePlat(

IdtypePlat int,

NomtypePlat varchar(30),

primary key (IdtypePlat)

);

insert into typePlat values

(1, 'Entrée'),

(2, 'Plat Principale'),

(3, 'Fromage'),

(4, 'Dessert');

create table consommation(

IdPlat int,

IdPersonnel int,

datecons date,

quantite int default 1,

primary key (IdPlat, IdPersonnel)

);

insert into consommation values


(1, 1, '2010-12-12' , 1),

(1, 2, '2011-01-03' , 2);

insert into consommation (IdPlat, IdPersonnel, quantite) values

(3, 5 , 1);

create table personnel(

Idpersonnel int,

nom varchar(30),

prenom varchar(30),

primary key (Idpersonnel)

);

select * from Plat;

select * from typePlat;

select * from consommation;

select * from personnel;

select * from personnel order by nom;

select p.NomPlat from consommation c ,Plat p where c.IdPlat = p.IdPlat and datecons = '2010-12-12';

select p.NomPlat

from personnel e, consommation c, Plat p

where e.Idpersonnel = c.Idpersonnel and c.IdPlat = p.IdPlat and e.nom = 'salmi' and c.datecons = '2010-
12-12';

select nom, sum(quantite) from consommation c, Personnel p where c.IdPersonnel = p.IdPersonnel


group by IdPersonnel, nom;

select avg(quantite) from consommation where IdPlat = 3;

select * from Personnel where IdPersonnel not in (select IdPersonnel from consommation);

select sum(quantite) from consommation group by IdPlat having sum(quantite) >= all (select
sum(quantite) from consommation group by IdPlat) ;

select count(IdPlat) from consommation group by IdPlat having count(IdPlat) >= 10 ;


insert into typePlat values

(3, 'Fromage');

delete from typePlat where NomtypePlat = 'Fromage';

update typePlat set NomtypePlat = 'Steak Frites' where IdtypePlat = 1;

alter table consommation add column heurcon time(3) generated always as (datecons + 1) stored;

alter table consommation drop column heurcon;

truncate table consommation;

You might also like