Sunteți pe pagina 1din 13

PROIECT

BAZE DE DATE


Piticas Razvan
Grupa 1046, Seria D, An II
A Deinirea sc!e"ei #azei $e $ate % ta#e&e '"ini" 4( cu &e)*turi +i a&te
restrictii $e inte)ritate 'CREATE TAB,E(, p-pu&ate 'I.SERT(/
create table furnizori(
cod_furniz varchar2(5),
nume_furniz varchar2(20),
tara_furniz varchar2(12),
constraint furnizori_pk primary key(cod_furniz));
create table produse(
cod_prod varchar2(5),
den_prod varchar2(5),
cod_furniz varchar2(5),
pret_intrare number(12,!),
pret_iesire number(12,!),
stoc number(12,!),
constraint produse_pk primary key(cod_prod),
constraint produse_furnizori_fk forei"n key(cod_furniz) references furnizori);
create table clienti(
cod_client varchar2(5),
nume_client varchar2(0),
localit_client varchar2(15),
data_n date,
constraint clienti_pk primary key(cod_client));
create table comenzi(
cod_comanda varchar2(5),
cod_client varchar2(5),
data_comanda date,
data_livrare date,
constraint comenzi_pk primary key(cod_comanda),
constraint comenzi_clienti_fk forei"n key(cod_client) references clienti);
create table rindc(
cod_comanda varchar2(5),
cod_prod varchar2(5),
nr_prod number() not null,
constraint rindc_pk primary key(cod_comanda,cod_prod),
constraint rindc_comenzi_fk forei"n key(cod_comanda) references comenzi,
constraint rindc_produse_fk forei"n key(cod_prod) references produse);
#$%&'()%'
*)+_#$%&'( &$,-_#$%&'( ./%/_#$%&'(
0%)+$1-
*)+_0%)+ +-&_0%)+ *)+_#$%&'( 0%-._'&.%/%- 0%-._'-1'%- 1.)*
*2'-&.'
*)+_*2'-&. &$,-_*2'-&. 2)*/2'._*2'-&. +/./_&
*),-&('
*)+_*),/&+/ *)+_*2'-&. +/./_*),/&+/ +/./_2'3%/%-
%'&+*
*)+_*),/&+/ *)+_0%)+ &%_0%)+
14 1526 insert into furnizori values(7%'87,7%iho7,7)landa7);
1526 insert into furnizori values(79%)7,79rohe7,79ermania7);
1526 insert into furnizori values(72/$7,72aufen7,7-lvetia7);
1526 insert into furnizori values(7-$%)*7,7-uroceramica7,7*ehia7);
1526 insert into furnizori values(7:2$7,7:ludi7,79ermania7);
1526 insert into furnizori values(7;':7,7;ika7,7*ehia7);
*)+_# &$,-_#$%&'( ./%/_#$%&'(
<<<<< <<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<
%'8 %iho )landa
9%) 9rohe 9ermania
2/$ 2aufen -lvetia
-$%)* -uroceramica *ehia
:2$ :ludi 9ermania
;': ;ika *ehia
24 1526 insert into produse values(70017,7=aterie
dus7,7:2$7,715>7,71?@,!7,72007);
1526 insert into produse values(70027,7=aterie
cada7,79%)7,7107,71!@,57,71507);
1526 insert into produse values(7007,7*uier7,79%)7,707,7!,57,71007);
1526 insert into produse values(700!7,70olicioara
cristal7,79%)7,7!17,7!?,157,7
107);
1526 insert into produse values(70057,70olicioara7,72/$7,757,7@,157,7?07);
1526 insert into produse values(700>7,71uport
prosop7,7;':7,7?7,7!2,257,7@07);
1526 insert into produse values(700?7,7*abina dus7,7%'87,72?27,712,A7,707);
1526 insert into produse values(700A7,7*ada hidromasaB7, 72/$7, 7?A@7,
7@0?,57,707);
1526 insert into produse values(700@7,70icior
chiuveta7,7:2$7,71207,71A7,7!07);
1526 insert into produse values(70107,7+ulap mic simplu7, 7-$%)*7,
71007,71157,7557);
*)+_0 +-&_0%)+ *)+_# 0%-._'&.%/%- 0%-._'-1'%- 1.)*
<<<<< <<<<<<<<<<<<<<<<<<< <<<<<<<<<< <<<<< <<<<<<<<<<<< <<<<<<<<<<<<<<<<<
<<<<<<<<<<
001 =aterie dus :2$ 15> 1?@,! 200
002 =aterie cada 9%) 10 1!@,5 150
00 *uier 9%) 0 !,5 100
00! 0olicioara cristal 9%) !1 !?,15 10
005 0olicioara 2/$ 5 @,15 ?0
00> 1uport prosop ;': ? !2,25 @0
00? *abina dus %'8 2?2 12,A 0
00A *ada hidromasaB 2/$ ?A@ @0?,5 0
00@ 0icior chiuveta :2$ 120 1A !0
010 +ulap mic simplu -$%)* 100 115 55
4 1526 insert into clienti values(717,7/n"helmob 1/7,7'asi7,to_date(7110@1@5@7,7d
dmmyyyy7));
1526 insert into clienti values(727,7'lia 1/7,7=rasov7,to_date(720051@>?7,7ddmm
yyyy7));
1526 insert into clienti values(77,78eraa 1/7,7=ucuresti7,to_date(70?0@1@??7,7
ddmmyyyy7));
1526 insert into clienti values(7!7,7%omdor 1/7,7#ocsani7,to_date(71@121@>!7,7d
dmmyyyy7));
1526 insert into clienti values(757,79avan *onstantin7,7'asi7,to_date(710021@5A
7,7ddmmyyyy7));
1526 insert into clienti values(7>7,7.oader /delina7,7=ucuresti7,to_date(71?0!1
@?A7,7ddmmyyyy7));
1526 insert into clienti values(7?7,7=adea =o"dan7,7*alarasi7,to_date(7250>1@>>
7,7ddmmyyyy7));
1526 insert into clienti values(7A7,7%adulescu ,aria7,7=ucuresti7,to_date(7250A
1@?!7,7ddmmyyyy7));
*)+_* &$,-_*2'-&. 2)*/2'._*2'-&. +/./_&
<<<<< <<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<
1 /n"helmob 1/ 'asi 11<0@<1@5@
2 'lia 1/ =rasov 20<05<1@>?
8eraa 1/ =ucuresti 0?<0@<1@??
! %omdor 1/ #ocsani 1@<12<1@>!
5 9avan *onstantin 'asi 10<02<1@5A
> .oader /delina =ucuresti 1?<0!<1@?A
? =adea =o"dan *alarasi 25<0><1@>>
A %adulescu ,aria =ucuresti 25<0A<1@?!
!4 1526 insert into comenzi values(717,717,to_date (72!0!0>7,7ddmmyy7),
to_date(702050>7,7ddmmyy7));
1526 insert into comenzi values(727,757,to_date(71@050>7,7ddmmyy7),
to_date(72A050>7,7ddmmyy7));
1526 insert into comenzi values(77,7>7,to_date(71@050>7,7ddmmyy7),
to_date(72>050>7,7ddmmyy7));
1526 insert into comenzi values(7!7,77,to_date(7210?0>7,7ddmmyy7),
to_date(700?0>7,7ddmmyy7));
1526 insert into comenzi values(757,7A7,to_date(715100>7,7ddmmyy7),
to_date(725100>7,7ddmmyy7));
1526 insert into comenzi values(7>7,7>7,to_date(71?110>7,7ddmmyy7),
to_date(720110>7,7ddmmyy7));
*)+_*) *)+_* +/./_*),/& +/./_2'3%/
<<<<<<<<< <<<<<<<<< <<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<
1 1 2!<0!<200> 02<05<200>
2 5 1@<05<200> 2A<05<200>
> 1@<05<200> 2><05<200>
! 21<0?<200> 0<0?<200>
5 A 15<10<200> 25<10<200>
> > 1?<11<200> 20<11<200>
54 1526 insert into rindc values(717,7007,7?7);
1526 insert into rindc values(717,700>7,7107);
1526 insert into rindc values(727,70107,7>7);
1526 insert into rindc values(77,700?7,717);
1526 insert into rindc values(7!7,70057,7@7);
1526 insert into rindc values(7!7,7007,7@7);
1526 insert into rindc values(757,700?7,7?7);
1526 insert into rindc values(7>7,70017,757);
*)+_* *)+_0 &%_0%)+
<<<<<<<<< <<<<<<<<< <<<<<<<<<<<<<
1 00 ?
1 00> 10
2 010 >
00? 1
! 005 @
! 00 @
5 00? ?
> 001 5
B 0 e1e"p&e variate cu A,TER TAB,E, pe c-&-ane +i pe restric2ii/
14 'n tabela 0%)+$1-, sa se aloce pentru campul cod_prod doar
caractere, in loc de 5
alter table produse modify(cod_prod varchar2());
24 1a se adau"e in tabela #$%&'()%' coloana cont_bancar
alter table furnizori add(cont_bancar varchar2(5));
4 1a se stear"a din tabela #$%&'()%' coloana creata
anterior(cont_bancar)
alter table furnizori drop column cont_bacar;
!4 1a se dezactiveze cheia primara a tabelei %'&+*
alter table rindc disable constraint rindc_pk;
54 1a se reactiveze cheia primara a tabelei %'&+*
alter table rindc enable constraint rindc_pk;
C 0 e1e"p&e variate cu -pera2ii&e $e actua&izare a $ate&-r 'c-"enzi&e D3,
% 4PDATE, DE,ETE, 53ERGE6 pentru 7nre)istrari(/
14 1a se stear"a din tabela 0%)+$1- produsele furnizate de firma
:ludi (cod :2$)
alter table rindc disable constraint rindc_produse_fk;
delete from produse Chere cod_furnizDE:2$E;
Frollback;G
Falter table rindc enable constraint rindc_produse_fk;G
24 1a se stear"a clientii din 'asi si #ocsani
alter table comenzi disable constraint comenzi_clienti_fk;
delete from clienti Chere localit_client in(H'asiH,H#ocsaniH);
Frollback;G
Falter table comenzi enable constraint comenzi_clienti_fk;G

4 1a se mareasca preturile de iesire ale tuturor produselor cu 2I
update produse set pret_iesireDpret_iesireJ1402;
Frollback;G
!4 1a se maresca stocul cu cate 5 produse pentru produsele furnizate
de 9rohe (cod 9%))
update produse set stocDstocK5 Chere cod_furnizDE9%)E;
Frollback;G
54 1a se modifice localitatea clientului 9avan *onstantin in =ucuresti
update clienti set localit_clientDE=ucurestiE Chere nume_clientDE9avan
*onstantinE;
Frollback;G
D 3ini" 10 e1e"p&e cu inter-)*ri c8t "ai variate 'SE,ECT(9
4ti&izarea -perat-ri&-r $e c-"paratie
4ti&izarea unc2ii&-r &a nive& $e r8n$ 'upper, su#str, $ec-$e, case,
nv&, t-:$ate, t-:c!ar(
4ti&izarea unctii&-r $e )rup si c-n$itii asupra acest-ra
GRO4P B;, <A=I.G
>-in?uri 'I..ER, O4TER(
4ti&izarea -perat-ri&-r 4.IO., 3I.4S, I.TERSECT
Su#cereri 'cereri i"#ricate(
5Cereri ierar!ice6
14 1a se afiseze datele de livrare si localitatile in care trebuie facute
livrarile din lunile mai si iunie 200>
1526 select data_livrare, localit_client from comenzi c, clienti cl
Chere c4cod_clientDcl4cod_client and c4data_comanda betCeen
to_date(701050>7,7ddmmyy7) and to_date(7010?0>7,7ddmmyy7)
order by cl4localit_client;
+/./_2'3%/ 2)*/2'._*2'-&.
<<<<<<<<<<<<<< <<<<<<<<<<<<<<<
2><05<200> =ucuresti
2A<05<200> 'asi
24 1a se afiseze denumirea produselor si numele furnizorilor pentru
produsele cu pretul de intrare mai mare decat 100
1526 select den_prod, nume_furniz from produse p, furnizori f Chere
p4cod_furn izDf4cod_furniz and p4pret_intrare6100;
+-&_0%)+ &$,-_#$%&'(
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<
*abina dus %iho
=aterie cada 9rohe
*ada hidromasaB 2aufen
0icior chiuveta :ludi
=aterie dus :ludi
4 1a se afiseze numele si codurile clientilor din 'asi
1526 select nume_client, cod_client from clienti Chere
localit_clientD7'asi7;
&$,-_*2'-&. *)+_*
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<
/n"helmob 1/ 1
9avan *onstantin 5
!4 1a se afiseze comenzile care contin 2 produse diferite
1526 select cod_comanda from rindc "roup by cod_comanda havin"
count(J)D2;
*)+_*
<<<<<
1
!
54 1a se calculeze valoarea comenzii 2
1526 select pret_iesireJnr_prod from produse p, rindc r Chere
p4cod_prodDr4cod_prod and r4cod_comandaD2;
0%-._'-1'%-J&%_0%)+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>@0
>4 1a se calculeze de cate ori a fost comandat fiecare produs
1526 select cod_prod, count(J) from rindc "roup by cod_prod order by
cod_prod;
*)+_0 *)$&.(J)
<<<<<<<<< <<<<<<<<<<<
00 2
005 1
00> 1
00? 2
010 1
?4 1a se afiseze produsele care nu au fost comandate
1526 select den_prod from rindc r , produse p Chere
r4cod_prod(K)Dp4cod_prod and r4cod_prod is null;
+-&_0%)+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
0olicioara cristal
0icior chiuveta
*ada hidromasaB
=aterie cada
A4 1a se afiseze clientii nascuti in aprilie si data lor de nastere
1526 select nume_client, data_n from clienti Chere
to_char(data_n,7mm7)D70!7;
&$,-_*2'-&. +/./_&
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<
.oader /delina 1?<0!<1@?A
@4 1a se afiseze numarul de furnizori din fiecare tara
1526 select distinct(tara_furniz),count(J) from furnizori "roup by
tara_furniz;
./%/_#$%&'( *)$&.(J)
<<<<<<<<<<<< <<<<<<<<<<
*ehia 2
9ermania 2
)landa 1
-lvetia 1
104 1a se selecteze toate produsele fabricate in 9ermania
1526 select den_prod from produse Chere cod_furniz in(select cod_furniz
from furnizori Chere tara_furnizD79ermania7);
+-&_0%)+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
=aterie dus
=aterie cada
*uier
0olicioara cristal
0icior chiuveta
114 0entru fiecare comanda, sa se afiseze numele clientului si localitatea
in care trebuie livrata comanda
1526 select cod_comanda, nume_client, localit_client from clienti cl,
comenzi c Chere cl4cod_clientDc4cod_client order by cod_comanda;
*)+_* &$,-_*2'-&. 2)*/2'._*2'-&.
<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<
1 /n"helmob 1/ 'asi
2 9avan *onstantin 'asi
.oader /delina =ucuresti
! 8eraa 1/ =ucuresti
5 %adulescu ,aria =ucuresti
> .oader /delina =ucuresti
124 1a se afiseze produsele care au stocul 0
1526 select cod_prod, den_prod from produse Chere stocD707;
*)+ +-&_0%)+
<<< <<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
00? *abina dus
00A *ada hidromasaB
14 1a se afiseze stocul tuturor produselor comandate
1526 select distinct(p4cod_prod), p4den_prod, p4stoc from produse2 p,
rindc r Chere r4cod_prodDp4cod_prod order by cod_prod;
*)+ +-&_0%)+ 1.)*
<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<
001 =aterie dus 200
00 *uier 100
005 0olicioara ?0
00> 1uport prosop @0
00? *abina dus 0
010 +ulap mic simplu 55
1!4 1a se afiseze produsul cu cel mai mare pret de intrare
1526 select den_prod, pret_intrare from produse Chere
pret_intrareD(select maL(pret_intrare) from produse2);
+-&_0%)+ 0%-._'&.%/%-
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<
*ada hidromasaB ?A@
E 0 e1e"p&e cu )estiunea a&t-r -#iecte a&e #azei $e $ate9 ve$eri 'se p-t
rea&iza vie@?uri cu cerinte&e $e &a punctu& D(, parti2ii, in$ec+i ,
sin-ni"e, secvente/
14 1a se realizeze o vedere care sa contina denumirea produselor,
preturile lor de iesire si furnizorii pentru fiecare produs
1526 create vieC v_produse as select den_prod,pret_iesire, nume_furniz
from produse p, furnizori f Chere p4cod_furnizDf4cod_furniz;
24 1a se creeze un indeL la tabela 0%)+$1-
1526 create indeL i_produse on produse (den_prod);
4 1a se creeze un sinonim pentru tabela #$%&'()%'
1526 create synonym firme for furnizori;
!41a se stear"a sinonimul tabelei furnizori
1526 drop synonym firme;