1 | SET FOREIGN_KEY_CHECKS = 0;
|
---|
2 | DROP TABLE IF EXISTS Objekt;
|
---|
3 | DROP TABLE IF EXISTS Vo_Izgradba;
|
---|
4 | DROP TABLE IF EXISTS Gotov;
|
---|
5 | DROP TABLE IF EXISTS Nadzor;
|
---|
6 | DROP TABLE IF EXISTS Podizveduvac;
|
---|
7 | DROP TABLE IF EXISTS Rabotnik;
|
---|
8 | DROP TABLE IF EXISTS Dobavuvac;
|
---|
9 | DROP TABLE IF EXISTS Nabavka;
|
---|
10 | DROP TABLE IF EXISTS Korisnik;
|
---|
11 | DROP TABLE IF EXISTS Sopstvenik;
|
---|
12 | DROP TABLE IF EXISTS Raboti_Na;
|
---|
13 | DROP TABLE IF EXISTS Raboti_Za;
|
---|
14 | DROP TABLE IF EXISTS Nadgleduva;
|
---|
15 | DROP TABLE IF EXISTS Pobaruva;
|
---|
16 | DROP TABLE IF EXISTS Nameneta_Za;
|
---|
17 | DROP TABLE IF EXISTS Odobruva;
|
---|
18 | DROP TABLE IF EXISTS Oddrzuva;
|
---|
19 | DROP TABLE IF EXISTS Ispolnuva;
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | CREATE TABLE Objekt (
|
---|
24 | Objekt_ID INT UNIQUE NOT NULL,
|
---|
25 | Tip VARCHAR(100),
|
---|
26 | Adresa VARCHAR(100),
|
---|
27 | CONSTRAINT Objekt PRIMARY KEY (Objekt_ID)
|
---|
28 | );
|
---|
29 |
|
---|
30 | CREATE TABLE Vo_Izgradba (
|
---|
31 | Objekt_ID INT NOT NULL UNIQUE,
|
---|
32 | Budzet FLOAT,
|
---|
33 | CONSTRAINT Vo_Izgradba FOREIGN KEY (Objekt_ID) REFERENCES Objekt (Objekt_ID)
|
---|
34 | );
|
---|
35 |
|
---|
36 | CREATE TABLE Gotov (
|
---|
37 | Objekt_ID INT NOT NULL UNIQUE,
|
---|
38 | CONSTRAINT Gotov FOREIGN KEY (Objekt_ID) REFERENCES Objekt (Objekt_ID)
|
---|
39 | );
|
---|
40 |
|
---|
41 | CREATE TABLE Nadzor (
|
---|
42 | Nadzor_Ime VARCHAR(50) NOT NULL,
|
---|
43 | Plata INT,
|
---|
44 | Kvalifikacii VARCHAR(50),
|
---|
45 | Firma VARCHAR(50),
|
---|
46 | UID INT NOT NULL UNIQUE,
|
---|
47 | CONSTRAINT Nadzor PRIMARY KEY (Nadzor_Ime, Firma),
|
---|
48 | CONSTRAINT Nadzor FOREIGN KEY (UID) REFERENCES Korisnik (UID)
|
---|
49 | );
|
---|
50 |
|
---|
51 | CREATE TABLE Podizveduvac (
|
---|
52 | Podizveduvac_Ime VARCHAR(50) NOT NULL UNIQUE,
|
---|
53 | Struka VARCHAR(50) NOT NULL,
|
---|
54 | Br_vraboteni INT NOT NULL,
|
---|
55 | Saatnica FLOAT NOT NULL,
|
---|
56 | UID INT NOT NULL UNIQUE,
|
---|
57 | CONSTRAINT Podizveduvac PRIMARY KEY (Podizveduvac_Ime),
|
---|
58 | CONSTRAINT Podizveduvac FOREIGN KEY (UID) REFERENCES Korisnik (UID)
|
---|
59 | );
|
---|
60 |
|
---|
61 | CREATE TABLE Rabotnik (
|
---|
62 | Maticen_br VARCHAR(13) NOT NULL UNIQUE,
|
---|
63 | Ime VARCHAR(50) NOT NULL,
|
---|
64 | Seniornost VARCHAR(50) NOT NULL,
|
---|
65 | CONSTRAINT Rabotnik PRIMARY KEY (Maticen_br)
|
---|
66 | );
|
---|
67 |
|
---|
68 | CREATE TABLE Dobavuvac (
|
---|
69 | Dobavuvac_Ime VARCHAR(50) NOT NULL UNIQUE,
|
---|
70 | Klasa VARCHAR(50) NOT NULL,
|
---|
71 | Tip VARCHAR(50) NOT NULL,
|
---|
72 | Poteklo VARCHAR(50) NOT NULL,
|
---|
73 | CONSTRAINT Dobavuvac PRIMARY KEY (Dobavuvac_Ime)
|
---|
74 | );
|
---|
75 |
|
---|
76 | CREATE TABLE Nabavka (
|
---|
77 | Nabavka_ID INT NOT NULL UNIQUE,
|
---|
78 | Datum date NOT NULL,
|
---|
79 | Cena FLOAT NOT NULL,
|
---|
80 | Kolicina FLOAT NOT NULL,
|
---|
81 | Predmet VARCHAR(100) NOT NULL,
|
---|
82 | CONSTRAINT Nabavka PRIMARY KEY (Nabavka_ID)
|
---|
83 | );
|
---|
84 |
|
---|
85 | CREATE TABLE Korisnik(
|
---|
86 | UID INT NOT NULL UNIQUE,
|
---|
87 | Username VARCHAR(50) NOT NULL UNIQUE,
|
---|
88 | Password VARCHAR(72) NOT NULL,
|
---|
89 | Privilegii INT NOT NULL,
|
---|
90 | CONSTRAINT Korisnik PRIMARY KEY (UID)
|
---|
91 | );
|
---|
92 |
|
---|
93 | CREATE TABLE Sopstvenik(
|
---|
94 | UID INT NOT NULL UNIQUE,
|
---|
95 | CONSTRAINT Sopstvenik FOREIGN KEY (UID) REFERENCES Korisnik (UID)
|
---|
96 | );
|
---|
97 |
|
---|
98 | CREATE TABLE Raboti_Na (
|
---|
99 | Objekt_ID INT,
|
---|
100 | Podizveduvac_Ime VARCHAR(50),
|
---|
101 | Saati INT,
|
---|
102 | PRIMARY KEY (Objekt_ID, Podizveduvac_Ime),
|
---|
103 | FOREIGN KEY (Objekt_ID) REFERENCES Objekt(Objekt_ID),
|
---|
104 | FOREIGN KEY (Podizveduvac_Ime) REFERENCES Podizveduvac(Podizveduvac_Ime)
|
---|
105 | );
|
---|
106 |
|
---|
107 | CREATE TABLE Raboti_Za (
|
---|
108 | Maticen_br VARCHAR(13),
|
---|
109 | Podizveduvac_Ime VARCHAR(50),
|
---|
110 | PRIMARY KEY (Maticen_br, Podizveduvac_Ime),
|
---|
111 | FOREIGN KEY (Maticen_br) REFERENCES Rabotnik(Maticen_br),
|
---|
112 | FOREIGN KEY (Podizveduvac_Ime) REFERENCES Podizveduvac(Podizveduvac_Ime)
|
---|
113 | );
|
---|
114 |
|
---|
115 | CREATE TABLE Nadgleduva (
|
---|
116 | Objekt_ID INT,
|
---|
117 | Nadzor_Ime VARCHAR(50),
|
---|
118 | PRIMARY KEY (Objekt_ID, Nadzor_Ime),
|
---|
119 | FOREIGN KEY (Objekt_ID) REFERENCES Objekt(Objekt_ID),
|
---|
120 | FOREIGN KEY (Nadzor_Ime) REFERENCES Nadzor(Nadzor_Ime)
|
---|
121 | );
|
---|
122 |
|
---|
123 | CREATE TABLE Pobaruva (
|
---|
124 | Nabavka_ID INT,
|
---|
125 | Podizveduvac_Ime VARCHAR(50),
|
---|
126 | PRIMARY KEY (Nabavka_ID, Podizveduvac_Ime),
|
---|
127 | FOREIGN KEY (Nabavka_ID) REFERENCES Nabavka(Nabavka_ID),
|
---|
128 | FOREIGN KEY (Podizveduvac_Ime) REFERENCES Podizveduvac(Podizveduvac_Ime)
|
---|
129 | );
|
---|
130 |
|
---|
131 | CREATE TABLE Odobruva (
|
---|
132 | Nabavka_ID INT,
|
---|
133 | Nadzor_Ime VARCHAR(100),
|
---|
134 | PRIMARY KEY (Nabavka_ID, Nadzor_Ime),
|
---|
135 | FOREIGN KEY (Nabavka_ID) REFERENCES Nabavka(Nabavka_ID),
|
---|
136 | FOREIGN KEY (Nadzor_Ime) REFERENCES Nadzor(Nadzor_Ime)
|
---|
137 | );
|
---|
138 |
|
---|
139 | CREATE TABLE Nameneta_Za (
|
---|
140 | Nabavka_ID INT,
|
---|
141 | Objekt_ID INT,
|
---|
142 | PRIMARY KEY (Nabavka_ID, Objekt_ID),
|
---|
143 | FOREIGN KEY (Nabavka_ID) REFERENCES Nabavka(Nabavka_ID),
|
---|
144 | FOREIGN KEY (Objekt_ID) REFERENCES Objekt(Objekt_ID)
|
---|
145 | );
|
---|
146 |
|
---|
147 | CREATE TABLE Ispolnuva (
|
---|
148 | Nabavka_ID INT,
|
---|
149 | Dobavuvac_Ime VARCHAR(50),
|
---|
150 | PRIMARY KEY (Nabavka_ID, Dobavuvac_Ime),
|
---|
151 | FOREIGN KEY (Nabavka_ID) REFERENCES Nabavka(Nabavka_ID),
|
---|
152 | FOREIGN KEY (Dobavuvac_Ime) REFERENCES Dobavuvac(Dobavuvac_Ime)
|
---|
153 | );
|
---|
154 |
|
---|
155 | CREATE TABLE Oddrzuva (
|
---|
156 | Objekt_ID INT,
|
---|
157 | Podizveduvac_Ime VARCHAR(50),
|
---|
158 | Saati INT,
|
---|
159 | PRIMARY KEY (Objekt_ID, Podizveduvac_Ime),
|
---|
160 | FOREIGN KEY (Objekt_ID) REFERENCES Objekt(Objekt_ID),
|
---|
161 | FOREIGN KEY (Podizveduvac_Ime) REFERENCES Podizveduvac(Podizveduvac_Ime)
|
---|
162 | );
|
---|
163 |
|
---|
164 | SET FOREIGN_KEY_CHECKS = 1; |
---|