Sei sulla pagina 1di 2

create table party(

id number not null,


cod varchar2(50) not null,
nume varchar2(200),
cnp number,
district_id number not null,
primary key (id),
constraint district_id foreign key (district_id)
references district(id),
oras varchar2(200),
adresa varchar2(200),
sector varchar2(200),
telefon varchar2(50),
sex varchar2(1),
functie varchar2(100),
id_parent_party number
);

create table country(


id number not null primary key,
cod varchar2(50) not null,
nume varchar2(200) not null
);

CREATE TABLE district (


id number not null,
cod varchar2(50) NOT NULL,
nume varchar2(200) not null,
id_country number not null,
PRIMARY KEY (id),
CONSTRAINT id_country FOREIGN KEY (id_country)
REFERENCES country(id)
);

create table store(


id number not null primary key,
cod varchar2(50) not null,
nume varchar2(200)
);

create table prod_categ(


id number not null primary key,
cod varchar2(50) not null,
nume varchar2(200) not null
);

create table product(


id number not null,
cod varchar2(50) not null,
nume varchar2(200) not null,
id_prod_categ number not null,
primary key(id),
constraint id_prod_categ foreign key (id_prod_categ)
references prod_categ(id)
);

create table borrowed_products(


id number not null,
id_store number,
id_party_customer number,
id_product number,
primary key (id),
constraint id_store foreign key (id_store)
references store(id),
constraint id_party_customer foreign key(id_party_customer)
references party(id),
constraint id_product foreign key (id_product)
references product(id),
pret_vanzare number,
qty number,
cod_event varchar2(50),
data_event date not null,
tip_event vcarchar2(1), - aici trebuie sa fac cu check
data_retur date
);

ALTER TABLE borrowed_products


ADD constraint id_product foreign key (id_product)
references product(id);

tip_event vcarchar2(1) check (tip_event in ('C','I'))