Vous êtes sur la page 1sur 4

SQL> create user Sebbartp1 identified by sebbartp1;

Utilisateur créé.

SQL> GRANT DBA TO Sebbartp1;

Autorisation de privilèges (GRANT) acceptée.


SQL> connect Sebbartp1;
Entrez le mot de passe : *********
Connecté.
Connecté.
SQL> CREATE TABLE Produit(CodeP number,DésignationP varchar(20),QauntitéS
number,PrixU number);

Table créée.

SQL> Create table Fournisseur(CodeF number,NomF varchar(20),Ville varchar(20));

Table créée.

SQL> Create table Commande(Ncom number,CodeP number,CodeF number,QteCom number);

Table créée.

SQL> alter table Produit add constraint PK_Produit primary key(CodeP);

Table modifiée.

SQL> alter table Fournisseur add constraint PK_Fournisseur primary key (CodeF);

Table modifiée.

SQL> alter table Commande add constraint PK_Commande primary key (NCom);

Table modifiée.

SQL> alter table Commande add constraint FK_Commande_Produit foreign key


(CodeP)references Produit (
CodeP)on delete cascade;

Table modifiée.

SQL> alter table Commande add constraint FK_Commande_Fournisseur foreign key


(CodeF)references Fourn
isseur(CodeF)on delete cascade;

Table modifiée.

SQL> alter table Produit add constraint UQ_Produit


unique(DésignationP,QauntitéS,PrixU);

Table modifiée.

SQL> alter table Fournisseur add constraint UQ_Fournisseur unique(NomF,Ville);

Table modifiée.

SQL> alter table Commande add constraint UQ_Commande unique(QteCom);


Table modifiée.

SQL> alter table Produit add constraint limite check(QauntitéS>=0 and


QauntitéS<=100);

Table modifiée.

SQL> alter table Fournisseur add constraint Ville check(Ville


in('ORAN','TLEMCEN','MOSTAGANEM'));

Table modifiée.

SQL> insert into Produit values(1,'Serveur réseaux',5,40000);

1 ligne créée.

SQL> insert into Produit values(2,'Epson c 44+',10,5950);

1 ligne créée.

SQL> insert into Produit values(3,'HP desk jet3420',10,5750);

1 ligne créée.

SQL> insert into Produit values(4,'HP laser jet 1005W' ,7,5600);

1 ligne créée.

SQL> insert into Produit values(5,'UPS 500va',20,3500);

1 ligne créée.

SQL> insert into Produit values(6,'APC 500 va' ,10,8500);

1 ligne créée.

SQL> insert into Produit values(7,'Mffpm610' ,17,17500);

1 ligne créée.

SQL> insert into Fournisseur values(1, 'DRIOUA' ,'ORAN');

1 ligne créée.

SQL> insert into Fournisseur values(2,'ABBASI','MOSTAGANEM');

1 ligne créée.

SQL> insert into Fournisseur values(3,'AMRAN','TLEMCEN');

1 ligne créée.

SQL> insert into Fournisseur values(4,'BEN YOUCEF','ORAN');

1 ligne créée.
SQL> insert into Commande values(1,1,1,15);
1 ligne créée.

SQL> insert into Commande values(2,3,1,120);

1 ligne créée.

SQL> insert into Commande Values(3,5,3,100);

1 ligne créée.

SQL> insert into Commande values(4,6,4,10);

1 ligne créée.

SQL> COMMIT;

Validation effectuée.

SQL> Truncate table Commande;

Table tronquée.

SQL> Select *From Commande;

aucune ligne sélectionnée


SQL> CREATE SEQUENCE S_Com Start with 1 Increment by 1;

Séquence créée.

SQL> insert into Commande values(S_Com.nextval,1,1,15);

1 ligne créée.

SQL> insert into Commande values(S_Com.nextval,3,1,120);

1 ligne créée.

SQL> insert into Commande values(S_Com.nextval,5,3,100);

1 ligne créée.

SQL> insert into Commande values(S_Com.nextval,6,4,10);

1 ligne créée.

SQL> Select count(CodeP) from Produit;

COUNT(CODEP)
------------
7

SQL> select Max(PrixU) from Produit;

MAX(PRIXU)
----------
40000

SQL> select Min(PrixU) from Produit;


MIN(PRIXU)
----------
3500

SQL> select AVG(PrixU) from Produit;

AVG(PRIXU)
----------
12400

SQL> select DésignationP,NomF,PrixU*QteCom as montant from Produit p,Fournisseur


f,Commande c where
p.CodeP=c.CodeP and f.CodeF=c.CodeF;

DÉSIGNATIONP NOMF MONTANT


-------------------- -------------------- ----------
Serveur réseaux DRIOUA 600000
HP desk jet3420 DRIOUA 690000
UPS 500va AMRAN 350000
APC 500 va BEN YOUCEF 85000

SQL> create view vue as select DésignationP,NomF,PrixU*QteCom as montant from


Produit p,Fournisseur
f,Commande c where p.CodeP=c.CodeP and f.CodeF=c.CodeF;

Vue créée.

SQL> Update Produit set PrixU=7000 where CodeP=1;

1 ligne mise à jour.

Vous aimerez peut-être aussi