0% ont trouvé ce document utile (0 vote)
15 vues5 pages

Guide SQL pour Gestion de Données

Le document décrit l'utilisation de SQLPLUS pour créer et interroger des tables dans une base de données. Il contient des commandes SQL pour créer des tables, insérer des données, faire des requêtes de sélection, de mise à jour et de suppression.

Transféré par

Abdo Kolamni
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats TXT, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
15 vues5 pages

Guide SQL pour Gestion de Données

Le document décrit l'utilisation de SQLPLUS pour créer et interroger des tables dans une base de données. Il contient des commandes SQL pour créer des tables, insérer des données, faire des requêtes de sélection, de mise à jour et de suppression.

Transféré par

Abdo Kolamni
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats TXT, PDF, TXT ou lisez en ligne sur Scribd

Outil de travail : SQLPLUS

creation d'un compte de travail(user)


1-connectez vous en tant que adminis

1-commande : Connect SYSTEM


than saisir mot de passe

commande 2 : Create user USERNAME identified by Password;


3 : Grant connect, resource to USERNAME;

pr se connecter sur le nouveau utilisateur : Connect USERNAME/Password

TP1_SQL

Create table Fournisseur( FID char(3),


FNOM char(30),
STATUT int,
VILLE char(20),
primary key(FID)
);
Create table Produit( PID char(3),
PNOM char(30),
COULEUR char(15),
POIDS int,
PRIX int,
primary key(PID) );

Create table ProduitFourni(PID char(3),


FID char(3),
QTE int,
primary key(PID,FID),
foreign key(PID) references Produit,
foreign key(FID) references Fournisseur) );
alter table add DL char(6);
alter table ProduitFourni modify DL DATE;

create table Employe as select * from Fournisseur ;

Conclusion : quand on affiche les deux tableaux fournisseur et Employe , on trouve


que la propri�t� NOT NULL de l'attribut FID n'existe pas dans le tableau
Employe .

drop table Employe

Comment afficher la liste des tables ?


Select table_name
from USER_tables // �a veut dire affiche la liste des table de
USER , on peut afficher index , clusters ou n'importe quel object avc m fa�on

Parie 2 : INSERTION DE DONNEES

Q2.1 INSERT INTO Fournisseur values("Fo","ManarTec",20,"tanger")


// there's a second way where u can change the order of the attributs :
// Q2.2Insert into Fournisseur (FNOM,VILLE,STATUT,FID) values
('Pseudo','Nador',30,'FO');

Q2.3 @(and drag the file the teacher gave u) ;// this inserts informations in ur
tables .

partie 3 : Requetes SQL

o) select table_name
from USERS_Tables ;

a) Q3.1 select * from Produit; // the * stands for ALL ATRIBUTS


Q3.2 select VILLE from Fournisseur where FNOM!='NULL'; // When u need to show
One attribue , u replace * by its name in the command

Q3.3 select FID,STATUT from Fournisseur where VILLE='Tanger';


Q3.4 select FID,STATUT from Fournisseur where VILLE='Tanger' AND STATUT>='20';

Interrogation avec r�sultat ordonn� :


select FID,STATUT from Fournisseur where VILLE='Tanger' Order by STATUT desc;

Q3.6
select FNOM
from Fournisseur f, ProduitFourni pf
where [Link]=pf AND [Link]='P2';
Q3.7

Interrogation avec ALL :


Q3.8
select distinct FNOM
from Fournisseur
where FID != ALL( select FID
from ProduitFourni
where PID='P2');
Q3.9
Select FID
from Fournisseur
Where Statut >= ALL ( Select Statut
from Fournisseur );
Q3.10
select FNOM
from Fournisseur
where exists ( select *
from ProduitFourni
where PID='P2'
AND [Link]=[Link]);

Q3.11
select FNOM
from Fournisseur
where not exists ( select *
from ProduitFourni
where PID='P2'
AND [Link]=[Link]);

Q3.12
select FNOM
from Fournisseur
where exists ( select *
from ProduitFourni
where [Link]=[Link]
AND PID = ALL(select PID from Produit));

Q3.13
select PID
from Produit
where POIDS>=120
union
select PID
from ProduitFourni
where FID='F2' ;

Q3.14
select distinct [Link],[Link]
from Fournisseur f1,Fournisseur f2
where [Link]=[Link]
AND [Link]!=[Link];

Q3.15
select distinct FID
from Fournisseur
where Statut<any(Select Statut
from Fournisseur);

Q3.16
select FNOM
from Fournisseur
where FID in ( select FID
from ProduitFourni
where PID='P2');

Q3.17
select FNOM
from Fournisseur
where FID in( select FID
from ProduitFourni
where PID in ( Select PID
from Produit
where COULEUR='OR'));

Q3.18
Select distinct FID
from ProduitFourni
where FID in ( select FID
from ProduitFourni
where PID in ( select PID
from ProduitFourni
where FID='F2'));

Q3.19
Select PID from ProduitFourni
Group by PID
having count(FID)>1;

Q3.20
SELECT DISTINCT FID
from Fournisseur
where VILLE in ( select VILLE
from Fournisseur
where FID='F1');
Q3.22
select distinct PNOM,POIDS/1000
from Produit ;

Q3.23
select count(FID)
from Fournisseur;

Q3.24
select count(distinct FID)
from ProduitFourni
where PID is not NULL;

Q3.25
select count(DL)
from ProduitFourni
where PID='P2';

Q3.26
select SUM(QTE)
from ProduitFourni
where PID='P2';

Q3.27
select FID
from Fournisseur
where Statut < any( select Statut
from Fournisseur);

Q3.28
select PID,SUM(QTE)
from ProduitFourni
group by PID;

Q3.29
select PID
from ProduitFourni
group by PID
having count(FID)>1;

Manipulation de donnees :

Q4.1
update Produit
set COULEUR='jaune',
POIDS=POIDS+5
Where PID='P2';

Q4.2
update Fournisseur
set STATUT=2*STATUT
where VILLE='Nador';

Q4.3
update ProduitFourni
set QTE=0
where FID in (select FID
from Fournisseur
where VILLE='Nador');

Q4.4
on ne peut pas modifier la cl�

Q4.5
insert into Produit(PID,PNOM,COULEUR,POIDS) Values('P7','BOULON','GRISE',2);
// On ne peut pas car on a deja P7 dans PID , et comme c'est la cl� elle peut pas
deteriminer deux produit diff;

Q4.6
create table TEMP(Pid) as select PID
from ProduitFourni
where FID='F2';

Q4.7
delete TEMP where PID='P1';

Q4.8
drop table TEMP;

Partie5 : Shema relationnel/user et m�tabase


Q5.1
select object_name,object_type from USER_objects;
Q5.2
// other infos appear on the screen .
Q5.3
select COLUMN_NAME from USER_TAB_COLUMNS
where TABLE_Name='FOURNISSEUR'; // Fournisseur doit etre obligatoirement ecrite en
MAJ ;

Vous aimerez peut-être aussi