2 BD Auto

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

drop database if exists AutoStyle;

create database AutoStyle;

use AutoStyle;

/* Tabele */

create table magazin(


id int not null primary key,
adresa varchar(40) not null,
oras varchar(30) not null,
judet varchar(30) not null,
nr_tel varchar(20) not null);

create table angajat(


id int not null auto_increment primary key,
nume varchar(20) not null,
prenume varchar(20) not null,
pozitie varchar(15) not null,
salariu int not null,
data_angajare date not null,
parola varchar(20) not null,
id_magazin int not null,
id_departament int not null);

create table departament(


id int not null primary key,
nume varchar(30) not null);

create table client(


id int not null primary key,
nume varchar(20) not null,
prenume varchar(20) not null,
oras varchar(20) not null,
judet varchar(20) not null,
nr_tel varchar(20) not null,
mod_de_plata varchar(15) not null,
id_magazin int not null);

create table comanda(


id int not null primary key,
data_comanda date not null,
total_plata int default 0,
id_angajat int not null,
id_client int not null);

create table comandaDetalii(


id_comanda int not null,
id_produs int not null,
cantitate int not null,
cantitate_livrata int default 0,
primary key(id_comanda,id_produs));

create table produs(


id int not null primary key,
nume varchar(30) not null,
pret int not null,
descriere varchar(40),
unitate_de_masura varchar(15));

create table stoc(


id_produs int not null,
id_magazin int not null,
cantitate int default 0,
primary key(id_produs,id_magazin));

/* Constrangeri */

alter table angajat


add constraint fk_angajat_magazin
foreign key(id_magazin)
references magazin(id)
on update cascade
on delete cascade;

alter table angajat


add constraint fk_angajat_departament
foreign key(id_departament)
references departament(id)
on update cascade
on delete cascade;

alter table client


add constraint fk_client_magazin
foreign key(id_magazin)
references magazin(id)
on update cascade
on delete cascade;

alter table comanda


add constraint fk_comanda_angajat
foreign key(id_angajat)
references angajat(id)
on update cascade
on delete cascade;

alter table comanda


add constraint fk_comanda_client
foreign key(id_client)
references client(id)
on update cascade
on delete cascade;

alter table comandaDetalii


add constraint fk_comandaDetalii_comanda
foreign key(id_comanda)
references comanda(id)
on update cascade
on delete cascade;

alter table comandaDetalii


add constraint fk_comandaDetalii_produs
foreign key(id_produs)
references produs(id)
on update cascade
on delete cascade;
alter table stoc
add constraint fk_stoc_produs
foreign key(id_produs)
references produs(id)
on update cascade
on delete cascade;

alter table stoc


add constraint fk_stoc_magazin
foreign key(id_magazin)
references magazin(id)
on update cascade
on delete cascade;

/* Magazin */
INSERT INTO magazin
VALUES(1, 'str. Aurel Vlaicu', 'Cluj-Napoca', 'Cluj', '0758412554'),
(2, 'str. Amzei', 'Timisoara', 'Timis', '0745821335'),
(3, 'str. Alunis', 'Iasi', 'Iasi', '0745021658');

/* Produs */
INSERT INTO produs
VALUES(1, 'Ulei Motor Castrol 5W30', 55, 'Motor', 'litru'),
(2, 'Lichid de frana', 48, 'DOT4', 'litru'),
(3, 'Bujie', 31, 'Motor benzina', 'bucata'),
(4, 'Filtru de aer', 43, 'Motor', 'bucata'),
(5, 'Ulei Motor Mobil 5W40', 28, 'Motor', 'litru'),
(6, 'Ulei Motor Castrol Edge 5W30', 60, 'Motor', 'litru'),
(7, 'Disc ambreiaj', 80, 'Distributie', 'bucata'),
(8, 'Kit distributie', 1000, 'Distributie', 'bucata'),
(9, 'Bucsa', 30, 'Suspensie', 'bucata'),
(10, 'Capete de bara', 150, 'Directie', 'set'),
(11, 'Amortizor', 120, 'Suspensie', 'bucata');

/* Stoc */
INSERT INTO stoc
VALUES(1, 1, 10),
(1, 2, 5),
(1, 3, 7),
(2, 1, 2),
(2, 2, 5),
(2, 3, 7),
(3, 1, 8),
(3, 2, 6),
(3, 3, 3),
(4, 1, 8),
(4, 2, 5),
(4, 3, 3),
(5, 1, 3),
(5, 2, 2),
(5, 3, 5),
(6, 1, 4),
(6, 2, 2),
(6, 3, 6),
(7, 1, 2),
(7, 2, 3),
(7, 3, 6),
(8, 1, 1),
(8, 2, 4),
(8, 3, 3),
(9, 1, 1),
(9, 2, 5),
(9, 3, 3),
(10, 1, 1),
(10, 2, 3),
(10, 3, 2),
(11, 1, 3),
(11, 2, 5),
(11, 3, 1);

/* Client */
INSERT INTO client
VALUES(1, 'Grigore', 'Roman', 'Satu Mare', 'Satu Mare', '0745778996', 'online', 2),
(2, 'Pop', 'Radu', 'Cluj-Napoca', 'Cluj', '0751124781', 'ramburs', 2),
(3, 'Popescu', 'Ioan', 'Cluj-Napoca', 'Cluj', '0741558997', 'cash', 2),
(4, 'Vasilescu', 'Ionel', 'Craiova', 'Dolj', '0744125998', 'card', 1),
(5, 'Pop', 'Daniel', 'Oradea', 'Bihor', '0741225667', 'card', 2);

/* Departament */
INSERT INTO departament
VALUES(1, 'Vanzare'),
(2, 'Distributie'),
(3, 'Administratie'),
(4, 'Livrare'),
(5, 'Contabilitate');

/* Angajat */
INSERT INTO angajat
VALUES(1, 'Marinescu', 'Marin', 'angajat', 1500, '2011-03-12', 'angajat1', 1, 1),
(2, 'Tudorescu', 'Tudor', 'director', 3000, '2006-01-10', 'director1', 2, 3),
(3, 'Pop', 'Daniel', 'angajat', 1800, '2010-06-28', 'angajat2', 2, 1),
(4, 'Grigore', 'Ionescu', 'director', 3300, '2009-05-01', 'director2', 1, 3),
(5, 'Pop', 'Ciprian', 'director', 2900, '2005-10-04', 'director3', 3, 3),
(6, 'Stan', 'Mircea', 'angajat', 1600, '2006-06-15', 'angajat3', 2, 4),
(7, 'Danciu', 'Anca', 'angajat', 1550, '2008-10-25', 'angajat4', 1, 4),
(8, 'Rus', 'Ioan', 'angajat', 2400, '2009-10-22', 'angajat5', 3, 1);

/* Comanda */
INSERT INTO comanda
VALUES(1, '2012-03-15', 75, 3, 3),
(2, '2011-05-15', 225, 8, 2),
(3, '2012-11-24', 70, 3, 1),
(4, '2011-12-20', 80, 1, 4);
/* Comanda Detalii */
INSERT INTO comandadetalii
VALUES(1, 3, 3, 3),
(2, 1, 5, 5),
(3, 4, 7, 7),
(4, 2, 2, 2);

You might also like