You are on page 1of 3

SQL COMMANDES BASE D E

DONNES

I-CREATION ET MANIPULATION DES TABLES

A/Creation des Tables


Create Table Produit
(Num _Prd Int(8),Desg Varchar(20), PV decimal(8,3)Not
Null,Qte_Stock Int(5) Default 0,Constraint PK Primary
Key(Num_Prd));
Create Table Commande
(Num_Comd Int(8),Num_Prd Int(8) RefrencesProduite(Num_
Prd),Qte Int(2) Check (Qte>5),Constraint FK Foreign Key
(Num_Prd) Refrences Produit , Constraint PK
PrimaryKey(Num_Comd));

B/Manipulation des tables


1. Ajouter un champ a une table:
Alter Table produit
Add Column(Code Int(8));
2. Ajouter une contrainte
Alter Table produit
Add Constraint C1 (Num_Prd Check(Num_Prd>6));
3. Supprimer un champ:
Alter Table Produit
Drop Column Qte_Stock;
4. Modifier un champ
Alter Table Produit
Modify(PV Int(5));
5. Supprimer Une Table
Drop Table Produit
6. Desactivé une Contrainte
Alter Table Produit
Disable Constraint PK;

II-MISE A JOUR DES DONNES

A/Ajouter une ligne


Insert Into Produit (Num_Prd,Desg,PV,Qte_Stock)
Values('1010','3eja bel Mayonaise','6400','5');

B/Supprimer une Lignes


Delete from Produit
Where (Qte_Stock=0); {Condition de suppresion}

C/Modification D'une ligne


Update Produit
Set Desg='Wa7do sec',PV='0' Where Num_Prd='1010';
D/Affichage (select)
Select * (Ou) list col
from nom-table
where condition;
Select Num_Prd
from Produit
where Num_Prd>55 and Qte_Stock=0;

E/Jointure (select)
Select col name
from Table1 T1,Table2 T2
Where T1.col = condition and T2.col2=Condition 2;
Exemple:
Select NomF
From Fournisseur F,PUF R,Usine U
where F.CodeF=R.CodeF and U.Code=R.CodeU and
U.ville=jendouba

You might also like