Académique Documents
Professionnel Documents
Culture Documents
use bdd_achat;
-- On crée DETAIL avec clé etrangères ssi déjà défini les clés primaires
-- des autres tables auparavant !!!!!
create table detail(numcom int, numpro int, qcom int,
primary key(numcom,numpro),
foreign key (numcom) references commande(numcom),
foreign key (numpro) references produit(numpro));
Show tables;
alter table produit add Poids int; alter table produit drop Poids;
Describe Customer;
select distinct categorie from client where ville='Casablanca' and categorie is not
null;
select numcli,nomcli,ville from client where nomcli<ville;
select nomcli from client where compte>10000 order by nomcli asc;
1.3.2
select * from client where ville in ('Rabat','Casablanca');
select * from client where ville='Rabat' or ville='Casablanca';
select * from client where ville not in('Rabat','Casablanca');
select * from client where categorie='D' and ville='Marrakech';
select * from client where categorie='C' or ville='Casablanca';
select * from client where categorie='C' and ville<>'Casablanca';
--Contraire de la question précedente C(AnB)=C(A)UC(B)
select * from client where categorie<>'C' or ville='Casablanca';
-- A ou B ou les deux :
SELECT * from client where categorie in('B','C') or ville in('Rabat','Kenitra');
-- A ou bien B :
select * from client where (categorie in ('B','C') and ville not in
('Rabat','Kenitra'))
or (categorie not in ('B','C') and ville in
('Rabat','Kenitra')) ;
---TP4 : Jointures :
141
select numcli from commande co, detail de
where co.numcom=de.numcom
and numpro=4;
SELECT numcli,nomcli from client where numcli not in (select numcli from commande)
and ville='rabat';
select distinct cl.numcli,nomcli from client cl,commande co where
cl.numcli<>all(select numcli from commande)and ville='rabat';
select distinct ville from client cl where cl.numcli =any(select co.numcli from
commande co,detail de where co.numcom=de.numcom and numpro=3) ;