1 | create table korisnici(
|
---|
2 | user_id integer primary key,
|
---|
3 | user_ime varchar(50) not null,
|
---|
4 | user_prezime varchar(50) not null,
|
---|
5 | user_password varchar(300) not null,
|
---|
6 | user_admin_id integer not null
|
---|
7 | --treba fk da se dodade do sistemski_admin so alter table
|
---|
8 | );
|
---|
9 | create table sistemski_admin(
|
---|
10 | user_id integer primary key,
|
---|
11 | constraint fk_user foreign key (user_id) references korisnici (user_id)
|
---|
12 | on delete cascade on update cascade
|
---|
13 | );
|
---|
14 |
|
---|
15 | alter table korisnici add constraint fk_korisnik_administriran foreign key (user_admin_id) references sistemski_admin(user_id)
|
---|
16 | on delete cascade on update cascade;
|
---|
17 |
|
---|
18 |
|
---|
19 | create table kupuvaci(
|
---|
20 | user_id integer primary key,
|
---|
21 | kupuvac_tel_broj varchar(50) not null,
|
---|
22 | constraint fk_user foreign key (user_id) references korisnici (user_id)
|
---|
23 | on delete cascade on update cascade
|
---|
24 | );
|
---|
25 |
|
---|
26 | create table dostavuvaci(
|
---|
27 | user_id integer primary key,
|
---|
28 | dostavuvac_vraboten_od date not null,
|
---|
29 | constraint fk_user foreign key (user_id) references korisnici (user_id)
|
---|
30 | on delete cascade on update cascade
|
---|
31 | );
|
---|
32 |
|
---|
33 | create table menadzeri(
|
---|
34 | user_id integer primary key,
|
---|
35 | menadzer_vraboten_od date not null,
|
---|
36 | constraint fk_user foreign key (user_id) references korisnici (user_id)
|
---|
37 | on delete cascade on update cascade
|
---|
38 | );
|
---|
39 |
|
---|
40 | create table restorani(
|
---|
41 | restoran_id integer primary key,
|
---|
42 | restoran_ime varchar(50) not null,
|
---|
43 | restoran_rejting integer not null,
|
---|
44 | restoran_adresa varchar(50) not NULL,
|
---|
45 | user_id integer NOT null,
|
---|
46 | constraint fk_restoran_menadzer foreign key(user_id) references menadzeri(user_id) on delete cascade on update cascade
|
---|
47 | );
|
---|
48 |
|
---|
49 | create table tip(
|
---|
50 | tip_id integer primary key,
|
---|
51 | tip_ime varchar(50) not null
|
---|
52 | );
|
---|
53 |
|
---|
54 | create table meni(
|
---|
55 | meni_id integer primary key,
|
---|
56 | tip_id integer not null,
|
---|
57 | restoran_id integer not null,
|
---|
58 | constraint fk_meni_tip foreign key (tip_id) references tip(tip_id) on delete cascade on update cascade,
|
---|
59 | constraint fk_meni_restoran foreign key (restoran_id) references restorani(restoran_id) on delete cascade on update cascade
|
---|
60 | );
|
---|
61 |
|
---|
62 | create table obroci(
|
---|
63 | obrok_id integer primary key,
|
---|
64 | obrok_opis varchar(10000) not null,
|
---|
65 | obrok_ime varchar(50) not null,
|
---|
66 | meni_id integer not null,
|
---|
67 | constraint fk_obrok_meni foreign key(meni_id) references meni(meni_id) on delete cascade on update cascade
|
---|
68 | );
|
---|
69 |
|
---|
70 | create table rezervacii(
|
---|
71 | rezervacija_id integer primary key,
|
---|
72 | rezervacija_vreme timestamp not null,
|
---|
73 | br_lugje integer not null,
|
---|
74 | rezervacija_status varchar(50) not null,
|
---|
75 | rezervacija_opis varchar(10000) not null,
|
---|
76 | restoran_id integer not null,
|
---|
77 | user_id integer not null,
|
---|
78 | constraint fk_rezervacija_restoran foreign key(restoran_id) references restorani(restoran_id) on delete cascade on update cascade,
|
---|
79 | constraint fk_rezervacija_kupuvac foreign key (user_id) references kupuvaci(user_id) on delete cascade on update cascade
|
---|
80 | );
|
---|
81 |
|
---|
82 | create table naracki(
|
---|
83 | naracka_id integer primary key,
|
---|
84 | naracana_na timestamp not null,
|
---|
85 | naracka_status varchar(50) not null,
|
---|
86 | naracka_cena_vkupna integer not null,
|
---|
87 | user_id_kupuvac integer not null,
|
---|
88 | user_id_dostavuvac integer not null,
|
---|
89 | constraint fk_naracka_kupuvac foreign key (user_id_kupuvac) references kupuvaci(user_id) on delete cascade on update cascade,
|
---|
90 | constraint fk_naracka_dostavuvac foreign key(user_id_dostavuvac) references dostavuvaci(user_id)on delete cascade on update cascade
|
---|
91 | );
|
---|
92 |
|
---|
93 | create table restorani_tel_broevi(
|
---|
94 | restoran_id integer not null,
|
---|
95 | broj varchar(50),
|
---|
96 | constraint pk_restorani_tel_broevi primary key (restoran_id,broj),
|
---|
97 | constraint fk_restorani_tel_broevi_restoran foreign key(restoran_id) references restorani(restoran_id) on delete cascade on update cascade
|
---|
98 | );
|
---|
99 |
|
---|
100 | create table cena(
|
---|
101 | obrok_id integer not null,
|
---|
102 | cena_id integer not null,
|
---|
103 | cena_iznos integer not null,
|
---|
104 | cena_vazi_od date not null,
|
---|
105 | cena_vazi_do date not null,
|
---|
106 | constraint pk_cena primary key (obrok_id,cena_id),
|
---|
107 | constraint fk_cena_obrok foreign key (obrok_id) references obroci(obrok_id) on delete cascade on update cascade
|
---|
108 | );
|
---|
109 |
|
---|
110 | create table rezervacija_rezervira_obrok(
|
---|
111 | rezervacija_id integer not null,
|
---|
112 | obrok_id integer not null,
|
---|
113 | constraint pk_rezervacija_rezervira_obrok primary key(rezervacija_id,obrok_id),
|
---|
114 | constraint fk_rezervacija_rezervira_obrok_rezervacija foreign key (rezervacija_id) references rezervacii(rezervacija_id) on delete cascade on update cascade,
|
---|
115 | constraint fk_rezervacija_rezervira_obrok_obrok foreign key (obrok_id) references obroci(obrok_id) on delete cascade on update cascade
|
---|
116 | );
|
---|
117 |
|
---|
118 | create table naracka_se_sostoi_od_obrok(
|
---|
119 | naracka_id integer not null,
|
---|
120 | obrok_id integer not null,
|
---|
121 | kolicina integer not null,
|
---|
122 | cena integer not null,
|
---|
123 | constraint pk_naracka_se_sostoi_od_obrok primary key (naracka_id,obrok_id),
|
---|
124 | constraint fk_naracka_se_sostoi_od_obrok_naracka foreign key (naracka_id) references naracki(naracka_id) on delete cascade on update cascade,
|
---|
125 | constraint fk_naracka_se_sostoi_od_obrok_obrok foreign key (obrok_id) references obroci(obrok_id) on delete cascade on update cascade
|
---|
126 | );
|
---|
127 | -- brisenje tabeli
|
---|
128 | drop table korisnici ;
|
---|
129 | drop table sistemski_admin ;
|
---|
130 | drop table kupuvaci ;
|
---|
131 | drop table dostavuvaci ;
|
---|
132 | drop table menadzeri ;
|
---|
133 | drop table restorani ;
|
---|
134 | drop table tip ;
|
---|
135 | drop table meni ;
|
---|
136 | drop table obroci ;
|
---|
137 | drop table rezervacii ;
|
---|
138 | drop table naracki ;
|
---|
139 | drop table restorani_tel_broevi ;
|
---|
140 | drop table cena ;
|
---|
141 | drop table rezervacija_rezervira_obrok ;
|
---|
142 | drop table naracka_se_sostoi_od_obrok ;
|
---|