2024-BD-BUT1-Sen/Code/TD2.sql
pvalarcher c3df27e4e5 BD Vin
2024-11-14 09:45:33 +01:00

46 lines
1.2 KiB
SQL

BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "Fournisseur" (
"numF" INTEGER,
"nomF" VARCHAR(20),
"CatF" INTEGER,
"VilF" VARCHAR(15),
PRIMARY KEY("numF")
);
CREATE TABLE IF NOT EXISTS "Piece" (
"numP" INTEGER,
"nomP" VARCHAR(20),
"clrP" VARCHER(20),
"PdsP" INTEGER,
PRIMARY KEY("numP")
);
CREATE TABLE IF NOT EXISTS "Livraison" (
"numF" INTEGER,
"numP" INTEGER,
"Qte" INTEGER,
PRIMARY KEY("numF","numP"),
FOREIGN KEY("numF") REFERENCES "Fournisseur",
FOREIGN KEY("numP") REFERENCES "Piece"
);
INSERT INTO "Fournisseur" ("numF","nomF","CatF","VilF") VALUES (1,'Bricorama',2,'Melun'),
(2,'Castorama',2,'Melun'),
(3,'Bricorama',2,'Sénart'),
(4,'Amazon',3,NULL),
(32,'Thales',2,'Paris');
INSERT INTO "Piece" ("numP","nomP","clrP","PdsP") VALUES (20,'Cle plate 24','Chrome',140),
(21,'Cle plate 18','Chrome',130),
(22,'Cle plate 16','Chrome',120),
(23,'Cle plate 14','Chrome',110),
(25,'engrenage','gris',310),
(34,'Boulon','Chrome',20);
INSERT INTO "Livraison" ("numF","numP","Qte") VALUES (32,25,40);
COMMIT;
select Livraison.numP, nomP from Livraison, Piece
where Livraison.numP = Piece.numP
-- num et nom des pieces qui contiennent "Cle plate" (dans leur nom)
select numP, nomP from Piece
where nomP like "Cle plate%"