1 | --drop schema if exists project cascade;
|
---|
2 | --create schema project;
|
---|
3 |
|
---|
4 | drop table vozaci_ima_kategorii;
|
---|
5 | drop table rezervacii_ima_za_vozila;
|
---|
6 | drop table vozaci_e_na_klienti;
|
---|
7 | drop table Avtomobili;
|
---|
8 | drop table Motori;
|
---|
9 | drop table Kombinja;
|
---|
10 | drop table MSteti;
|
---|
11 | drop table Parkirani;
|
---|
12 | drop table Servisi;
|
---|
13 | drop table ServisKompBr;
|
---|
14 | drop table ServisKomp;
|
---|
15 | drop table Vozila;
|
---|
16 | drop table Kategorii;
|
---|
17 | drop table IzdavSaloniBr;
|
---|
18 | drop table Lokacii;
|
---|
19 | drop table FizickiLBr;
|
---|
20 | drop table FizickiL;
|
---|
21 | drop table PravniL;
|
---|
22 | drop table Rezervacii;
|
---|
23 | drop table Naplati;
|
---|
24 | drop table Smetki;
|
---|
25 | drop table Dogovori;
|
---|
26 | drop table Klienti;
|
---|
27 | drop table VraboteniBr;
|
---|
28 | drop table Prodavachi;
|
---|
29 | drop table Menadzeri;
|
---|
30 | drop table Vraboteni;
|
---|
31 | drop table IzdavSaloni;
|
---|
32 | drop table VozaciBr;
|
---|
33 | drop table Vozaci;
|
---|
34 |
|
---|
35 | -------------------------------
|
---|
36 |
|
---|
37 | create table Kategorii (
|
---|
38 | idKat serial primary key,
|
---|
39 | tip varchar(3)
|
---|
40 | );
|
---|
41 |
|
---|
42 | create table Vozila (
|
---|
43 | idVozi integer primary key,
|
---|
44 | idKat integer,
|
---|
45 | model varchar(255),
|
---|
46 | marka varchar(255),
|
---|
47 | regTab varchar(255),
|
---|
48 | cenaVozi decimal,
|
---|
49 | constraint fk_idKat foreign key (idKat) references Kategorii (idKat)
|
---|
50 | );
|
---|
51 |
|
---|
52 | create table Avtomobili (
|
---|
53 | idVoziA integer primary key,
|
---|
54 | brSedista integer,
|
---|
55 | constraint fk_idVozi foreign key (idVoziA) references Vozila(idVozi)
|
---|
56 | );
|
---|
57 |
|
---|
58 | create table Motori (
|
---|
59 | idVoziM integer primary key,
|
---|
60 | kubikaza integer,
|
---|
61 | constraint fk_idVozi foreign key (idVoziM) references Vozila(idVozi)
|
---|
62 | );
|
---|
63 |
|
---|
64 | create table Kombinja (
|
---|
65 | idVoziK integer primary key,
|
---|
66 | brSedista integer,
|
---|
67 | nosivost integer,
|
---|
68 | constraint fk_idVozi foreign key (idVoziK) references Vozila(idVozi)
|
---|
69 | );
|
---|
70 |
|
---|
71 | create table IzdavSaloni (
|
---|
72 | idIS serial primary key
|
---|
73 | );
|
---|
74 |
|
---|
75 | create table IzdavSaloniBr (
|
---|
76 | idIS integer,
|
---|
77 | telBrIs char(9),
|
---|
78 | constraint pk_IzdavSaloniBr primary key (idIs, telBrIs),
|
---|
79 | constraint fk_IzdavSaloniBr foreign key (idIS) references IzdavSaloni(idIS)
|
---|
80 | );
|
---|
81 |
|
---|
82 | create table Klienti (
|
---|
83 | EMBGK char(13) primary key,
|
---|
84 | imeK varchar(255),
|
---|
85 | adresaK varchar(255),
|
---|
86 | primiumK boolean
|
---|
87 | );
|
---|
88 |
|
---|
89 | create table FizickiL (
|
---|
90 | EMBGKFL char(13) primary key,
|
---|
91 | constraint fk_FizickiL foreign key (EMBGKFL) references Klienti (EMBGK)
|
---|
92 | );
|
---|
93 |
|
---|
94 | create table FizickiLBr (
|
---|
95 | EMBGKFL char(13),
|
---|
96 | telBrFL char(9),
|
---|
97 | constraint pk_FizickiLBr primary key (EMBGKFL, telBrFL),
|
---|
98 | constraint fk_FizickiLBr foreign key (EMBGKFL) references FizickiL(EMBGKFL)
|
---|
99 | );
|
---|
100 |
|
---|
101 | create table PravniL (
|
---|
102 | EMBGKPL char(13) primary key,
|
---|
103 | direktor varchar(255),
|
---|
104 | constraint fk_PravniL foreign key (EMBGKPL) references Klienti (EMBGK)
|
---|
105 | );
|
---|
106 |
|
---|
107 | create table Dogovori (
|
---|
108 | idDog serial primary key,
|
---|
109 | EMBGK char(13) references Klienti(EMBGK),
|
---|
110 | idIS integer references IzdavSaloni(idIS),
|
---|
111 | cenaDog decimal,
|
---|
112 | sklucenNa date,
|
---|
113 | vaziDo date
|
---|
114 | );
|
---|
115 |
|
---|
116 | create table Lokacii (
|
---|
117 | idLok serial primary key,
|
---|
118 | idIS integer references IzdavSaloni(idIS),
|
---|
119 | adresaLok varchar(255),
|
---|
120 | gradLok varchar(255)
|
---|
121 | );
|
---|
122 |
|
---|
123 | create table Vozaci (
|
---|
124 | EMBGVoza char(13) primary key,
|
---|
125 | imeVoza varchar(255),
|
---|
126 | adresaVoza varchar(255),
|
---|
127 | vozackaD char(8)
|
---|
128 | );
|
---|
129 |
|
---|
130 | create table VozaciBr (
|
---|
131 | EMBGVoza char(13) references Vozaci(EMBGVoza),
|
---|
132 | telBrVoza char(9),
|
---|
133 | constraint pk_VozaciBr primary key (EMBGVoza, telBrVoza)
|
---|
134 | );
|
---|
135 |
|
---|
136 | create table MSteti (
|
---|
137 | idMS serial primary key,
|
---|
138 | idVozi integer references Vozila(idVozi),
|
---|
139 | EMBGVoza char(13) references Vozaci(EMBGVoza),
|
---|
140 | cenaMS decimal
|
---|
141 | );
|
---|
142 |
|
---|
143 | create table Vraboteni (
|
---|
144 | EMBGV char(13) primary key,
|
---|
145 | idIS integer references IzdavSaloni(idIS),
|
---|
146 | imeV varchar(255)
|
---|
147 | );
|
---|
148 |
|
---|
149 | create table VraboteniBr (
|
---|
150 | EMBGVBr char(13) references Vraboteni(EMBGV),
|
---|
151 | telBrV char(9),
|
---|
152 | constraint pk_VraboteniBr primary key (EMBGVBr, telBrV)
|
---|
153 | );
|
---|
154 |
|
---|
155 | create table Menadzeri (
|
---|
156 | EMBGVM char(13) primary key,
|
---|
157 | constraint fk_Menadzeri foreign key (EMBGVM) references Vraboteni(EMBGV)
|
---|
158 | );
|
---|
159 |
|
---|
160 | create table Prodavachi (
|
---|
161 | EMBGVP char(13) primary key,
|
---|
162 | EMBGVM char(13) references Menadzeri(EMBGVM),
|
---|
163 | constraint fk_Prodavachi foreign key (EMBGVP) references Vraboteni(EMBGV)
|
---|
164 | );
|
---|
165 |
|
---|
166 | create table Rezervacii (
|
---|
167 | idRez serial primary key,
|
---|
168 | EMBGVoza char(13) references Vozaci(EMBGVoza),
|
---|
169 | idDog integer references Dogovori(idDog),
|
---|
170 | naDatumRez date,
|
---|
171 | doDatumRez date
|
---|
172 | );
|
---|
173 |
|
---|
174 | create table ServisKomp (
|
---|
175 | brSK integer primary key,
|
---|
176 | imeSK varchar(255),
|
---|
177 | adresaSK varchar(255)
|
---|
178 | );
|
---|
179 |
|
---|
180 | create table ServisKompBr (
|
---|
181 | brSK integer references ServisKomp(brSK),
|
---|
182 | telBrSK char(9),
|
---|
183 | constraint pk_ServisKompBr primary key (brSK, telBrSK)
|
---|
184 | );
|
---|
185 |
|
---|
186 | create table Servisi (
|
---|
187 | brS serial primary key,
|
---|
188 | brSk integer references ServisKomp(brSK),
|
---|
189 | idVozi integer references Vozila(idVozi),
|
---|
190 | cenaS decimal,
|
---|
191 | naDatumS date
|
---|
192 | );
|
---|
193 |
|
---|
194 | create table Smetki (
|
---|
195 | brSm serial primary key,
|
---|
196 | idDog integer references Dogovori(idDog),
|
---|
197 | cenaSm decimal,
|
---|
198 | datumSm date
|
---|
199 | );
|
---|
200 |
|
---|
201 | create table Parkirani (
|
---|
202 | od date,
|
---|
203 | doD date,
|
---|
204 | idVozi integer references Vozila(idVozi),
|
---|
205 | idIS integer references IzdavSaloni(idIS),
|
---|
206 | constraint pk_Parkirani primary key (od, idVozi, idIS)
|
---|
207 | );
|
---|
208 |
|
---|
209 | create table Naplati (
|
---|
210 | idNap serial,
|
---|
211 | brSM integer references Smetki(brSm),
|
---|
212 | EMBGVP char(13) references Prodavachi(EMBGVP),
|
---|
213 | kesh boolean,
|
---|
214 | kartica boolean,
|
---|
215 | datumNap date,
|
---|
216 | constraint pk_Naplati primary key (idNap, brSM)
|
---|
217 | );
|
---|
218 |
|
---|
219 | create table rezervacii_ima_za_vozila (
|
---|
220 | idRez integer references Rezervacii(idRez),
|
---|
221 | idVozi integer references Vozila (idVozi),
|
---|
222 | constraint pk_rez_ima_za_vozi primary key (idRez, IdVozi)
|
---|
223 | );
|
---|
224 |
|
---|
225 | create table vozaci_e_na_klienti (
|
---|
226 | EMBGVoza char(13) references Vozaci(EMBGVoza),
|
---|
227 | EMBGK char(13) references Klienti(EMBGK),
|
---|
228 | constraint pk_voz_e_na_klienti primary key (EMBGVoza, EMBGK)
|
---|
229 | );
|
---|
230 |
|
---|
231 | create table vozaci_ima_kategorii (
|
---|
232 | EMBGVoza char(13) references Vozaci(EMBGVoza),
|
---|
233 | idKat integer references Kategorii(idKat),
|
---|
234 | constraint pk_voz_ima_kat primary key (EMBGVoza, idKat)
|
---|
235 | );
|
---|
236 |
|
---|
237 | alter table izdavsaloni
|
---|
238 | add imeSal varchar(255);
|
---|
239 |
|
---|
240 | alter table fizickilbr
|
---|
241 | alter column telbrfl type varchar(20);
|
---|
242 |
|
---|
243 | alter table izdavsalonibr
|
---|
244 | alter column telbris type varchar(20);
|
---|
245 |
|
---|
246 | alter table serviskompbr
|
---|
247 | alter column telbrsk type varchar(20);
|
---|
248 |
|
---|
249 | alter table vrabotenibr
|
---|
250 | alter column telbrv type varchar(20);
|
---|
251 |
|
---|
252 | alter table vozacibr
|
---|
253 | alter column telbrvoza type varchar(20); |
---|