Skip to document
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Proiect baze de date

Course

Sisteme de gestiune a bazelor de date (MLM5028)

27 Documents
Students shared 27 documents in this course
Academic year: 2016/2017
Uploaded by:
0followers
1Uploads
7upvotes

Comments

Please sign in or register to post comments.

Related Studylists

bd

Preview text

PROIECT BAZE DE DATE

SANDU MIHAELA-AMALIA

GRUPA 1082

CUPRINS:

1 bazei de date

  1. Schema bazei de date
  2. Scripturile CREATE TABLE
  3. Inserarile in tabele
  4. Interogari variate
  5. Gestiunea altor obiecte ale bazei de date.

2. Schema bazei de date

3.

4.

COMENZI_PRODUSE Id_Comanda Pret_comanda Id_Produs

COMENZI Id_Comanda Data_comanda Stare_comanda Modplata_comanda Id_Client

CLIENTI Id_Client Nume_client Prenume_client Cnp_client Adresa_client Telefon_client Datorii_client

1

FURNIZORI

Id_furnizor

Nume_furnizor

Adresa_furnizor

Datorie_catre_furnizor

PRODUSE Id_Produs Descriere_produs Pret_produs Tva_produs Id_Furnizor

1 1 ∞

1

1

1

3. Scripturile CREATE TABLE

a) Crearea tabelei CLIENTI

CREATE TABLE CLIENTI1:

id_client number PRIMARY KEY,

nume_client varchar2(120) NOT NULL,

prenume_client varchar2(120) NOT NULL,

cnp_client varchar2(120) NOT NULL,

adresa_client varchar2(120) NULL,

telefon_client varchar2(120) NOT NULL,

datorii_client integer NULL);

b) Crearea tabelei COMENZI:

CREATE TABLE COMENZI

(id_comanda integer NOT NULL PRIMARY KEY,

data_comanda date NOT NULL,

stare_comanda varchar2(20) NOT NULL,

modplata_comanda varchar2(25) NOT NULL,

Id_client number REFERENCES CLIENTI(id_client));

e) Crearea tabelei PRODUSE

CREATE TABLE PRODUSE

(id_produs integer NOT NULL PRIMARY KEY,

descriere_produs varchar2(200 ) NULL,

pret_produs number NOT NULL,

tva_produs number NULL,

Id_furnizor number REFERENCES FURNIZORI(id_furnizor));

4. Inserarile in tabele:

a) Inserari in tabela Furnizori:

Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(1,'Cord', 'Targoviste', 200); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(2,'Astoria', 'Gaesti', 0);

Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(3,'Manoil', 'Targoviste', 0); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(4,'Central', 'Targoviste', 0); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(5,'Elit', 'Targoviste', 120); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(6,'Grandi', 'Targoviste', 80); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(7,'Orbit', 'Targoviste', 0); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(8,'2Smart', 'Targoviste', 0); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(9,'Giusto', 'Targoviste', 0); Insert into FURNIZORI(Id_furnizor , nume_furnizor, adresa_furnizor, datorie_catre_furnizor) values(10,'Velpitar', 'Targoviste', 20);

Insert into CLIENTI1 (id_client , nume_client ,prenume_client ,cnp_client,adresa_client,telefon_client,datorii_client ) values(8,'Popescu','Adelina','a','str,nr',0251123456,0); Insert into CLIENTI1 (id_client , nume_client ,prenume_client ,cnp_client,adresa_client,telefon_client,datorii_client ) values(9,'Sandu','Mihaela','s','str,bl,ap',0732143564,0); Insert into CLIENTI1 (id_client , nume_client ,prenume_client ,cnp_client,adresa_client,telefon_client,datorii_client ) values(10,'Vasile','Maria','mvasile','str,bl,ap',0732143564,0);

c) Inserari in tabela Comenzi1:

insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (1, to_date('12-12-2018', 'dd-mm-yyyy'), 'livrat', 'cash',1); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (2, to_date('12-12-2018', 'dd-mm-yyyy'), 'nelivrat', 'N\A',5); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (3, to_date('27-12-2018', 'dd-mm-yyyy'), 'necunoscut', 'cash',4); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (4, to_date('04-12-2018', 'dd-mm-yyyy'), 'refuzat', 'N\A',3);

insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (5, to_date('09-12-2018', 'dd-mm-yyyy'), 'livrat', 'cash',2); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (6, to_date('12-03-2018', 'dd-mm-yyyy'), 'livrat', 'cash',6); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (7, to_date('04-04-2018', 'dd-mm-yyyy'), 'livrat', 'cash',8); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (8, to_date('15-10-2018', 'dd-mm-yyyy'), 'livrat', 'cash',7); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (9, to_date('19-08-2018', 'dd-mm-yyyy'), 'livrat', 'cash',9); insert into Comenzi1(id_comanda,data_comanda, stare_comanda, modplata_comanda,id_client) values (10, to_date('21-11-2018', 'dd-mm-yyyy'), 'livrat', 'cash',10);

d) Inserari in tabela Produse1:

insert into produse1(id_produs, descriere_produs, pret_produs, tva_produs, id_furnizor) values (1, 'paine', 1, 0, 10);

insert into comenzi_produse( id_comanda, pret_comanda) values (7,14); insert into comenzi_produse( id_comanda, pret_comanda) values (8,582); insert into comenzi_produse( id_comanda, pret_comanda) values (9,105); insert into comenzi_produse( id_comanda, pret_comanda) values (10,100);

5. Interogari variate

--Adaugare coloana Sex in tabela Clienti1:

ALTER TABLE CLIENTI1 ADD (SEX VARCHAR2(1));

--Se modifica marimea atributului nume_client din tbela Clienti1:

ALTER TABLE CLIENTI1 MODIFY (NUME_CLIENT VARCHAR(100));

--Se sterge coloana Sex din tabela Clienti1:

ALTER TABLE CLIENTI1 DROP COLUMN SEX;

--Sa se redenumeasca tabela Produse1 in Produse_vanzare

ALTER TABLE PRODUSE1 RENAME TO PRODUSE_VANZARE;

-- Se sterg randurile din Furnizori unde id_ul este inte 12 si 14

DELETE FROM FURNIZORI
WHERE ID_FURNIZOR IN( SELECT ID_FURNIZOR FROM FURNIZORI
WHERE ID_FURNIZOR BETWEEN 12 AND 14);

--Se selecteaza starea comenzii, data, numele clientului si datoria acstuia:

SELECT STARE_COMANDA, DATA_COMANDA, NUME_CLIENT,
DATORII_CLIENT
FROM COMENZI1 C, CLIENTI1 CL
WHERE C.ID_CLIENT=CL_CLIENT;

--Sa se afiseze datele din tabela FURNIZOR si pe cele comune din tabela PRODUSE_VANZARE:

SELECT * FROM FURNIZORI F LEFT OUTER JOIN PRODUSE_VANZARE P ON F.ID_FURNIZOR=P_FURNIZOR;

--Sa se afle pretul maxim din tabela PRODUSE_VANZARE:

SELECT MAX(PRET_PRODUS)PRET_MAXIM FROM
PRODUSE_VANZARE;

--Se face o tabela de back-up pentru cea de COMENZI1 si apoi se sterge:

CREATE TABLE CLIENTI1_BACKUP AS SELECT* FROM CLIENTI1;
DROP TABLE CLIENTI1_BACKUP;
WHERE P.ID_FURNIZOR=F_FURNIZOR;

--Afisam clientii care au datorii sub 70 lei folosind operatorul minus

SELECT ID_CLIENT, NUME_CLIENT, DATORII_CLIENT FROM CLIENTI MINUS SELECT ID_CLIENT, NUME_CLIENT, DATORII_CLIENT FROM CLIENTI WHERE DATORII_CLIENT>70;

--Afisam id-ul si pretul produsului folosind operatorul union:

SELECT ID_PRODUS
FROM PRODUSE_VANZARE
UNION
SELECT PRET_PRODUS
FROM PRODUSE_VANZARE;

--Se afiseaza numele si adresa clientilor care au datorii mai mari de 70 de lei folosind intersect: SELECT NUME_CLIENT, ADRESA_CLIENT FROM CLIENTI INTERSECT SELECT NUME_CLIENT, ADRESA_CLIENT FROM CLIENTI WHERE DATORII_CLIENT>70;

Was this document helpful?
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Proiect baze de date

Course: Sisteme de gestiune a bazelor de date (MLM5028)

27 Documents
Students shared 27 documents in this course
Was this document helpful?

This is a preview

Do you want full access? Go Premium and unlock all 25 pages
  • Access to all documents

  • Get Unlimited Downloads

  • Improve your grades

Upload

Share your documents to unlock

Already Premium?
PROIECT BAZE DE DATE
SANDU MIHAELA-AMALIA
GRUPA 1082
Clasificare BT: Uz Intern

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.