1 | create table Vraboteni(
|
---|
2 | id_vraboten serial ,
|
---|
3 | ime varchar(100) not null,
|
---|
4 | prezime varchar(100) not null,
|
---|
5 | embg varchar(13) not null,
|
---|
6 | datum_ragjanje date not null,
|
---|
7 | obrazovanie varchar(100) not null,
|
---|
8 | constraint pk_vraboten primary key (id_vraboten)
|
---|
9 | );
|
---|
10 | create table Menadzeri(
|
---|
11 | id_vraboten integer,
|
---|
12 | constraint pk_menadzer primary key (id_vraboten),
|
---|
13 | constraint fk_vraboteni_menadzer foreign key (id_vraboten)
|
---|
14 | references vraboteni(id_vraboten)
|
---|
15 | );
|
---|
16 | create table Direktor(
|
---|
17 | id_vraboten integer,
|
---|
18 | constraint pk_director primary key (id_vraboten),
|
---|
19 | constraint fk_vraboteni_direktor foreign key (id_vraboten)
|
---|
20 | references vraboteni(id_vraboten)
|
---|
21 | );
|
---|
22 | create table Magacioneri(
|
---|
23 | id_vraboten integer,
|
---|
24 | constraint pk_magacioner primary key (id_vraboten),
|
---|
25 | constraint fk_vraboteni_magacioner foreign key (id_vraboten)
|
---|
26 | references vraboteni(id_vraboten)
|
---|
27 | );
|
---|
28 | create table Shefovi(
|
---|
29 | id_vraboten integer,
|
---|
30 | constraint pk_shef primary key (id_vraboten),
|
---|
31 | constraint fk_vraboteni_shef foreign key (id_vraboten )
|
---|
32 | references vraboteni(id_vraboten)
|
---|
33 | );
|
---|
34 | create table Vraboteni_vo_proizvodstvo(
|
---|
35 | id_vraboten integer,
|
---|
36 | constraint pk_vrab_proizvodstvo primary key (id_vraboten),
|
---|
37 | constraint fk_vraboten_proizvodstvo foreign key(id_vraboten)
|
---|
38 | references vraboteni(id_vraboten)
|
---|
39 | );
|
---|
40 | create table Korisnik(
|
---|
41 | id_korisnik serial,
|
---|
42 | korisnicko_ime varchar(100) not null,
|
---|
43 | lozinka varchar(100) not null,
|
---|
44 | constraint pk_korisnik primary key(id_korisnik)
|
---|
45 | );
|
---|
46 | create table Delovi(
|
---|
47 | id_del serial,
|
---|
48 | vid_na_del varchar(100) not null,
|
---|
49 | cena double precision not null,
|
---|
50 | constraint pk_delovi primary key(id_del)
|
---|
51 | );
|
---|
52 | create table Materijali(
|
---|
53 | id_materijal serial,
|
---|
54 | velicina double precision not null,
|
---|
55 | naziv varchar(50) not null,
|
---|
56 | dostapen_broj integer not null,
|
---|
57 | constraint pk_materijal primary key (id_materijal)
|
---|
58 | );
|
---|
59 | create table Mashini(
|
---|
60 | id_mashina serial,
|
---|
61 | naziv varchar(50) not null,
|
---|
62 | constraint pr_mashina primary key (id_mashina)
|
---|
63 | );
|
---|
64 | create table Oddelenija(
|
---|
65 | id_oddelenie serial,
|
---|
66 | naziv varchar(30) not null,
|
---|
67 | constraint pk_oddelenie primary key(id_oddelenie)
|
---|
68 | );
|
---|
69 | create table Mebel(
|
---|
70 | id_mebel serial,
|
---|
71 | tip varchar(100) not null,
|
---|
72 | naziv varchar(50) not null,
|
---|
73 | cena double precision not null,
|
---|
74 | constraint pk_mebel primary key (id_mebel)
|
---|
75 | );
|
---|
76 | create table Klienti(
|
---|
77 | id_klient serial,
|
---|
78 | korisnicko_ime varchar(50) not null,
|
---|
79 | lozinka varchar(50) not null ,
|
---|
80 | prezime varchar(100) not null,
|
---|
81 | ime varchar(100) not null,
|
---|
82 | constraint pk_klienti primary key(id_klient)
|
---|
83 | );
|
---|
84 | create table Nalozi(
|
---|
85 | id_nalog serial ,
|
---|
86 | krajna_data date ,
|
---|
87 | pocetna_data date not null,
|
---|
88 | id_vraboten integer not null,
|
---|
89 | constraint pk_nalog primary key(id_nalog),
|
---|
90 | constraint fk_nalog_menagzer foreign key (id_vraboten) references Menadzeri(id_vraboten)
|
---|
91 | );
|
---|
92 | create table Naracka(
|
---|
93 | id_naracka serial,
|
---|
94 | datum_napravena date not null,
|
---|
95 | datum_isporacana date ,
|
---|
96 | naslov varchar(100) not null,
|
---|
97 | opis text not null,
|
---|
98 | vkupna_cena double precision,
|
---|
99 | id_klient integer not null,
|
---|
100 | constraint pk_naracka primary key (id_naracka),
|
---|
101 | constraint fk_naracal_klient foreign key (id_klient) references klienti(id_klient)
|
---|
102 | );
|
---|
103 | create table Dogovori(
|
---|
104 | id_dogovor serial,
|
---|
105 | pocetok date not null,
|
---|
106 | plata double precision not null,
|
---|
107 | kraj date not null,
|
---|
108 | aktiven smallint not null,
|
---|
109 | id_vraboten integer,
|
---|
110 | constraint pk_dogovor primary key(id_dogovor),
|
---|
111 | constraint fk_vraboten_dogovor foreign key (id_vraboten) references vraboteni(id_vraboten)
|
---|
112 | );
|
---|
113 | create table Evidencija_na_naracki(
|
---|
114 | id_evidencija serial,
|
---|
115 | datum date not null,
|
---|
116 | id_naracka integer not null,
|
---|
117 | constraint pk_evidencija_na_naracki primary key(id_evidencija),
|
---|
118 | constraint fk_naracka_za_evidencija foreign key (id_naracka) references naracka(id_naracka)
|
---|
119 | );
|
---|
120 | create table ima_napraveno_servis(
|
---|
121 | id_servis serial,
|
---|
122 | id_mashina integer not null,
|
---|
123 | datum date not null,
|
---|
124 | zabeleska text not null,
|
---|
125 | cena double precision not null,
|
---|
126 | constraint pk_servis primary key (id_servis,id_mashina),
|
---|
127 | constraint fk_mashina_servis foreign key(id_mashina) references mashini(id_mashina)
|
---|
128 | );
|
---|
129 | --relacii mxn
|
---|
130 | create table naracka_se_sostoi_od_mebel(
|
---|
131 | id_mebel integer,
|
---|
132 | id_naracka integer,
|
---|
133 | kolicina integer not null,
|
---|
134 | constraint pk_naracka_se_sostoi_od_mebel primary key (id_mebel,id_naracka),
|
---|
135 | constraint fk_naracka_se_sostoi_mebel foreign key(id_mebel) references mebel(id_mebel),
|
---|
136 | constraint fk_naracka_se_sostoi_naracka foreign key(id_naracka) references naracka(id_naracka)
|
---|
137 | );
|
---|
138 | create table dopolniteli_delovi_za_naracka(
|
---|
139 | id_naracka integer,
|
---|
140 | id_del integer ,
|
---|
141 | kolicina integer not null,
|
---|
142 | constraint pk_dopolnistelni_delovi primary key(id_naracka,id_del),
|
---|
143 | constraint fk_dopolnitelni_delovi_naracka foreign key (id_naracka) references naracka(id_naracka),
|
---|
144 | constraint fk_dopolnitelni_delovi_delovi foreign key (id_del) references delovi(id_del)
|
---|
145 | );
|
---|
146 | create table mebel_se_sostoi_od_delovi(
|
---|
147 | id_mebel integer ,
|
---|
148 | id_del integer,
|
---|
149 | kolicina integer not null,
|
---|
150 | constraint pk_mebel_se_sostoi_od_delovi primary key(id_mebel,id_del),
|
---|
151 | constraint fk_mebel_sostoi_od_delov_mebel foreign key (id_mebel) references mebel(id_mebel),
|
---|
152 | constraint fk_mebel_sostoi_od_delov_del foreign key (id_del) references delovi(id_del)
|
---|
153 | );
|
---|
154 | create table evidencija_naracki_izraboteni_delovi(
|
---|
155 | id_evidencija integer,
|
---|
156 | id_del integer,
|
---|
157 | br_na_zavrseni_delovi integer not null,
|
---|
158 | constraint pk_evidencija_naracki_izraboteni_delovi primary key(id_evidencija,id_del),
|
---|
159 | constraint fk_evidencija_naracki_izraboteni_delovi_evidencija foreign key (id_evidencija) references evidencija_na_naracki(id_evidencija),
|
---|
160 | constraint fk_evidencija_naracki_izraboteni_delovi_delovi foreign key(id_del) references delovi(id_del)
|
---|
161 | );
|
---|
162 |
|
---|
163 | --relacii nx1,nx1
|
---|
164 | create table nalozi_kreira_naracka(
|
---|
165 | id_nalog integer,
|
---|
166 | id_naracka integer not null,
|
---|
167 | constraint pk_nalozi_kreira_naracka primary key (id_nalog),
|
---|
168 | constraint fk_nalozi_kreira_naracka_nalog foreign key (id_nalog) references nalozi(id_nalog),
|
---|
169 | constraint fk_nalozi_kreira_naracka_naracka foreign key (id_naracka) references naracka(id_naracka)
|
---|
170 | );
|
---|
171 | create table evidencija_se_odnesuva_na_mebel(
|
---|
172 | id_evidencija integer,
|
---|
173 | id_mebel integer not null,
|
---|
174 | procenti_zavrsen double precision,
|
---|
175 | constraint pk_evidencija_se_odnesuva_na_mebel primary key (id_evidencija),
|
---|
176 | constraint fk_evidencija_se_odnesuva_na_mebel_evidencija foreign key (id_evidencija) references evidencija_na_naracki(id_evidencija),
|
---|
177 | constraint fk_evidencija_se_odnesuva_na_mebel_mebel foreign key (id_mebel) references mebel(id_mebel)
|
---|
178 | );
|
---|
179 | create table delovi_izraboteni_od_materijal(
|
---|
180 | id_del integer,
|
---|
181 | id_materijal integer not null,
|
---|
182 | constraint pk_delovi_izraboteni_od_materijal primary key (id_del),
|
---|
183 | constraint fk_delovi_izraboteni_od_materijal_delovi foreign key (id_del) references delovi(id_del),
|
---|
184 | constraint fk_delovi_izraboteni_od_materijal_materijal foreign key (id_materijal) references materijali(id_materijal)
|
---|
185 | );
|
---|
186 |
|
---|
187 | create table delovi_izraboteni_od_mashina(
|
---|
188 | id_del integer,
|
---|
189 | id_mashina integer not null,
|
---|
190 | constraint pk_delovi_izraboteni_od_mashina primary key (id_mashina,id_del),
|
---|
191 | constraint fk_delovi_izraboteni_od_mashina_del foreign key(id_del) references delovi(id_del),
|
---|
192 | constraint fk_delovi_izraboteni_od_mashina_mashina foreign key (id_mashina) references mashini(id_mashina)
|
---|
193 | );
|
---|
194 | create table mashina_pripaga_oddelenie(
|
---|
195 | id_mashina integer ,
|
---|
196 | id_oddelenie integer not null,
|
---|
197 | constraint pk_mashina_pripaga_oddelenie primary key (id_mashina),
|
---|
198 | constraint fk_mashina_prigaha_oddelenie_mashina foreign key (id_mashina) references mashini(id_mashina),
|
---|
199 | constraint fk_mashina_pripaga_oddelenie_oddelenie foreign key (id_oddelenie) references oddelenija(id_oddelenie)
|
---|
200 | );
|
---|
201 | create table vraboteni_se_korisnici(
|
---|
202 | id_vraboten integer,
|
---|
203 | id_korisnik integer,
|
---|
204 | constraint pk_korisnici_vraboteni primary key (id_vraboten),
|
---|
205 | constraint fk_korisnici_vraboteni_vraboten foreign key (id_vraboten)references vraboteni(id_vraboten),
|
---|
206 | constraint fk_korisnici_vraboteni_korisnik foreign key (id_korisnik) references korisnik(id_korisnik)
|
---|
207 | );
|
---|
208 | create table vraboteni_vo_proizvodstvo_raboti_vo_oddelenija(
|
---|
209 | id_vraboten integer,
|
---|
210 | id_oddelenie integer,
|
---|
211 | constraint pk_vraboteni_vo_proizvodstvo_raboti_vo_oddelenija primary key (id_vraboten),
|
---|
212 | constraint fk_vraboteni_vo_proizvodstvo_raboti_vo_odd_vraboteni foreign key (id_vraboten) references vraboteni_vo_proizvodstvo(id_vraboten),
|
---|
213 | constraint fk_vraboteni_vo_proizvodstvo_raboti_vo_odd_oddelenie foreign key (id_oddelenie)references oddelenija(id_oddelenie)
|
---|
214 | );
|
---|
215 |
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|