Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

create database correctedDB

select*from Client
select*from ArticolComandat
select*from Comenzi
select*from Produse
select*from Producatori
-- Create Clienti table
------------------------CREATE TABLE Client
(
id_client
char(10)
nume_client
char(50)
adresa_client
char(50)
oras_client
char(50)
stat_client
char(5)
Cod_Post_client
char(10)
tara_client
char(50)
contact_client
char(50)
email_client
char(255)
);

NOT NULL ,
NOT NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL

CREATE TABLE ArticolComandat


(
NumarComanda int
NOT
NumarArticol int
NOT
id_produs
char(10)
NOT
cantitate
int
NOT
pret_articol decimal(8,2) NOT
);

NULL
NULL
NULL
NULL
NULL

,
,
,
,

CREATE TABLE Comenzi


(
NumarComanda int
NOT NULL ,
DataComanda date
NOT NULL ,
id_client char(10) NOT NULL
);
CREATE TABLE Produse
(
id_produs
char(10)
NOT NULL
id_prod
char(10)
NOT NULL
Nume_produs char(255)
NOT NULL
pret_produs decimal(8,2) NOT NULL
desc_produs varchar(1000) NULL
);
------------------------ Create Producatori table
----------------------CREATE TABLE Producatori
(id_prod
char(10) NOT NULL ,
nume_prod
char(50) NOT NULL ,
adresa_prod char(50) NULL ,
oras_prod
char(50) NULL ,
stat_prod
char(5) NULL ,

,
,
,
,

Cod_Post_prod char(10) NULL ,


tara_prod
char(50) NULL
);
----------------------- Define primary keys
---------------------ALTER TABLE Client WITH NOCHECK ADD CONSTRAINT PK_Client PRIMARY KEY CLUSTERED
(id_client);
ALTER TABLE ArticolComandat WITH NOCHECK ADD CONSTRAINT PK_ArticolComandat
PRIMARY KEY CLUSTERED (NumarComanda,NumarArticol);
ALTER TABLE Comenzi WITH NOCHECK ADD CONSTRAINT PK_Comenzi PRIMARY KEY
CLUSTERED (NumarComanda);
ALTER TABLE Produse WITH NOCHECK ADD CONSTRAINT PK_Produse PRIMARY KEY
CLUSTERED (id_produs);
ALTER TABLE Producatori WITH NOCHECK ADD CONSTRAINT PK_Producatori PRIMARY KEY
CLUSTERED (id_prod);
----------------------- Define foreign keys
---------------------ALTER TABLE ArticolComandat ADD
CONSTRAINT FK_ArticolComandat_Comenzi FOREIGN KEY (NumarComanda) REFERENCES
Comenzi(NumarComanda),
CONSTRAINT FK_ArticolComandat_Produse FOREIGN KEY (id_produs) REFERENCES
Produse (id_produs);
ALTER TABLE Comenzi ADD
CONSTRAINT FK_Comenzi_Client FOREIGN KEY (id_client) REFERENCES Client
(id_client);
ALTER TABLE Produse ADD
CONSTRAINT FK_Produse_Producatori FOREIGN KEY (id_prod) REFERENCES Producatori
(id_prod);
-------------------------------------------------------------- Sams Teach Yourself SQL in 10 Minutes
-- http://www.forta.com/books/0672325675/
-- Example table population scripts for Microsoft SQL Server.
---------------------------------------------------------------------------------------- Populate Clienti table
--------------------------INSERT INTO Client (id_client, nume_client, adresa_client , oras_client,
stat_client, Cod_post_client, Tara_client, contact_client, email_client)
VALUES('1000000001', 'Vin TONUS', '200 Maria
Lana','Dubasari','DB','44444','RM','Joneta Susan', 'sales@villagetoys.com');
INSERT INTO Client (id_client, nume_client, adresa_client, oras_client,
stat_client, Cod_post_client, Tara_client, contact_client, email_client)
VALUES('1000000002', 'Casa Publica', '333 Sfanta Larisa Duca', 'Calaras',
'CA', '43333', 'RM', 'Mihai Garman',null);
INSERT INTO Client (id_client, nume_client, adresa_client, oras_client,
stat_client, Cod_post_client, Tara_client, contact_client, email_client)
VALUES('1000000003', 'Franzeluta', '1 Sfanta Piata', 'Marculesti', 'MC',
'42222', 'RM', 'Jicu Jordan', 'jjones@fun4all.com');
INSERT INTO Client (id_client, nume_client, adresa_client, oras_client,
stat_client, Cod_post_client, Tara_client, contact_client, email_client)
VALUES('1000000004', 'Franzeluta', '829 Reveniu', 'Dubasari', 'DB', '88888',
'RM', 'Dionis Stepan', 'dstephens@fun4all.com');

INSERT INTO Client (id_client, nume_client, adresa_client, oras_client,


stat_client, Cod_post_client, Tara_client, contact_client, email_client)
VALUES('1000000005', 'Magazin Jucarii', '4545 53rd Sturza', 'Chsinau', 'CH',
'54545', 'RM', 'Kiril Haruta',null);
-------------------------- Populate Producatori table
------------------------INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('BRS01','Belarus','123 Mai','Balti','MI','44444', 'RM');
INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('BRE02','Belarus Emp','500 Parc ','Aneni','OH','44333', 'RM');
INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('DLL01','Dorinel Huce','555 Higha','DosofTEI','CA','99999', 'RM');
INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('FRB01','Furdui','1000/5 str Averi','Noul Yorga','NY','11111', 'RM');
INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('FNG01','FurdUI','42 Galaxia Road','Londra', NULL,'88888', 'Anglia');
INSERT INTO Producatori(id_prod, nume_prod, adresa_prod, oras_prod, stat_prod,
Cod_Post_prod, Tara_prod)
VALUES('JTS01','Jigan','1 Ruesti','Paris', NULL,'45678', 'Franta');
--------------------------- Populate Produse table
-------------------------INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BR01', 'BRS01', '8 in poseta', 5.99, '8 inch teddy bear, comes with
cap and jacket');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BR02', 'BRS01', '12 in Traistra', 8.99, '12 inch teddy bear, comes
with cap and jacket');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BR03', 'BRS01', '18 in Jeanta', 11.99, '18 inch teddy bear, comes with
cap and jacket');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BNBG01', 'DLL01', 'Fuste', 3.49, 'Fish bean bag toy, complete with
bean bag worms with which to feed it');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BNBG02', 'DLL01', 'Blugi', 3.49, 'Bird bean bag toy, eggs are not
included');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('BNBG03', 'DLL01', 'Rabbit jeanta', 3.49, 'Rabbit bean bag toy, comes
with bean bag carrots');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('RGAN01', 'DLL01', 'Regina', 4.99, '18 inch Raggedy Ann doll');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('RYL01', 'FNG01', 'Rege ', 9.49, '12 inch king doll with royal garments
and crown');
INSERT INTO Produse(id_produs, id_prod, nume_produs, pret_produs, desc_produs)
VALUES('RYL02', 'FNG01', 'Cub Rubic', 9.49, '12 inch queen doll with royal
garments and crown');
------------------------- Populate Comenzi table
------------------------

INSERT INTO Comenzi(NumarComanda, DataComanda, id_client)


VALUES(20005, '2004-05-01', '1000000001');
INSERT INTO Comenzi(NumarComanda, DataComanda, id_client)
VALUES(20006, '2004-01-12', '1000000003');
INSERT INTO Comenzi(NumarComanda, DataComanda, id_client)
VALUES(20007, '2004-01-30', '1000000004');
INSERT INTO Comenzi(NumarComanda, DataComanda, id_client)
VALUES(20008, '2004-02-03', '1000000005');
INSERT INTO Comenzi(NumarComanda, DataComanda, id_client)
VALUES(20009, '2004-02-08', '1000000001');
----------------------------- Populate ArticolComandat table
---------------------------INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20005, 1, 'BR01', 100, 5.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20005, 2, 'BR03', 100, 10.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20006, 1, 'BR01', 20, 5.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20006, 2, 'BR02', 10, 8.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20006, 3, 'BR03', 10, 11.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20007, 1, 'BR03', 50, 11.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20007, 2, 'BNBG01', 100, 2.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20007, 3, 'BNBG02', 100, 2.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20007, 4, 'BNBG03', 100, 2.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20007, 5, 'RGAN01', 50, 4.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20008, 1, 'RGAN01', 5, 4.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20008, 2, 'BR03', 5, 11.99);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20008, 3, 'BNBG01', 10, 3.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)
VALUES(20008, 4, 'BNBG02', 10, 3.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs,
pret_articol)

cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,
cantitate,

VALUES(20008, 5, 'BNBG03', 10, 3.49);


INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs, cantitate,
pret_articol)
VALUES(20009, 1, 'BNBG01', 250, 2.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs, cantitate,
pret_articol)
VALUES(20009, 2, 'BNBG02', 250, 2.49);
INSERT INTO ArticolComandat(NumarComanda, NumarArticol, id_produs, cantitate,
pret_articol)
VALUES(20009, 3, 'BNBG03', 250, 2.49);

You might also like