RelationalDesign: Kreiranje.sql

File Kreiranje.sql, 4.1 KB (added by 201130, 2 years ago)
Line 
1create table project.Korisnik(
2id_korisnik serial primary key,
3ime_prezime varchar(100) not null,
4password_korisnik varchar(100) not null,
5kreiran_na_datum timestamp default now()
6);
7
8
9create table project.Kupuvac(
10id_korisnik serial primary key,
11mail varchar(100) not null,
12constraint fk_kupuvac foreign key (id_korisnik) references project.Korisnik (id_korisnik)
13);
14
15create table project.Admin_korisnik(
16id_korisnik serial primary key,
17constraint fk_admin foreign key (id_korisnik) references project.Korisnik (id_korisnik)
18);
19
20
21
22create table project.Dostavuvac(
23id_korisnik serial primary key,
24constraint fk_dostavuvac foreign key (id_korisnik) references project.Korisnik (id_korisnik)
25);
26
27
28
29create table project.Magacioner(
30id_korisnik serial primary key,
31id_magacin serial,
32constraint fk_magacioner_magacin foreign key(id_magacin) references project.Magacin (id_magacin),
33constraint fk_magacioner foreign key (id_korisnik) references project.Korisnik (id_korisnik)
34);
35
36
37create table project.TelefonskiBroj(
38id_korisnik serial references project.Kupuvac(id_korisnik),
39telefonski_broj varchar(50),
40constraint pk_telefonski_broj_ primary key (id_korisnik,telefonski_broj)
41);
42
43
44create table project.Naracka(
45id_naracka serial primary key,
46vkupno_suma integer not null,
47datum date not null,
48status varchar(50) not null,
49adresa varchar(100) not null,
50id_korisnik serial,
51constraint fk_kupuvac foreign key(id_korisnik) references project.Kupuvac (id_korisnik)
52);
53
54
55
56create table project.Dostava(
57id_korisnik serial,
58id_naracka serial,
59id_dostava serial primary key,
60datum date not null,
61status varchar(50) not null,
62constraint fk_kupuvac foreign key(id_korisnik) references project.Dostavuvac (id_korisnik),
63constraint fk_naracka foreign key (id_naracka) references project.Naracka (id_naracka)
64);
65
66
67
68create table project.Magacin(
69id_magacin serial primary key,
70lokacija varchar(50) not null
71);
72
73
74
75create table project.Kategorija(
76id_kategorija serial primary key,
77ime varchar(50) not null
78);
79
80
81create table project.Produkt(
82id_produkt serial primary key,
83ime varchar(50) not null,
84opis varchar(200),
85id_korisnik serial,
86constraint fk_produkt_admin foreign key (id_korisnik) references project.Admin_korisnik(id_korisnik)
87);
88
89
90create table project.Cena(
91id_produkt serial,
92cena_od date not null,
93cena_do date,
94iznos integer not null,
95constraint pk_cena primary key (id_produkt, cena_od),
96constraint fk_cena_produkt foreign key (id_produkt) references project.Produkt (id_produkt)
97);
98
99
100create table project.naracka_sodrzi_produkt(
101id_produkt serial,
102id_naracka serial,
103kolicina integer not null,
104cena integer not null,
105constraint pk_naracka_sodrzi_produkt primary key(id_produkt, id_naracka),
106constraint fk_n_s_p_p foreign key (id_produkt) references project.Produkt(id_produkt),
107constraint fk_n_s_p_n foreign key (id_naracka) references project.Naracka(id_naracka)
108);
109
110
111create table project.produkt_e_vo_magacin(
112id_produkt serial,
113id_magacin serial,
114kolicina integer not null,
115constraint pk_produkt_e_vo_magacin primary key(id_produkt, id_magacin),
116constraint fk_p_e_vo_m_p foreign key (id_produkt) references project.Produkt (id_produkt),
117constraint fk_p_e_vo_m_m foreign key (id_magacin) references project.Magacin (id_magacin)
118);
119
120
121
122create table project.produkt_e_od_kategorija(
123id_produkt serial,
124id_kategorija serial,
125constraint pk_produkt_e_od_kategorija primary key (id_produkt, id_kategorija),
126constraint fk_p_e_od_k_p foreign key (id_produkt) references project.Produkt(id_produkt),
127constraint fk_p_e_od_k_k foreign key (id_kategorija) references project.Kategorija(id_kategorija)
128);
129
130
131drop table project.Kupuvac;
132drop table project.Korisnik;
133drop table project.Admin_korisnik;
134drop table project.Dostavuvac;
135drop table project.Magacioner;
136drop table project.Telefonskibroj;
137drop table project.Dostava;
138drop table project.Magacin;
139drop table project.Naracka;
140drop table project.Kategorija;
141drop table project.Produkt;
142drop table project.Cena;
143drop table project.naracka_sodrzi_produkt;
144drop table project.produkt_e_vo_magacin;
145drop table project.produkt_e_od_kategorija;