source: source/_kreiranje_.sql

Last change on this file was 1563111, checked in by zlatko2810 <zlatko.stojanovski@…>, 2 years ago

all files

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[1563111]1-- DROP SCHEMA "Project";
2
3CREATE SCHEMA "Project" AUTHORIZATION db_202122z_va_prj_freeparkingspace_owner;
4
5create table Najava(
6Korisnicko_ime varchar(150) primary key,
7EMBG varchar(13) not null,
8Br_tel varchar(30) not null,
9Email varchar(150) not null,
10password varchar(50) not null,
11Ime varchar(150) not null,
12Prezime varchar(150) not null
13);
14
15create table Vraboten(
16Id_vraboten serial not null,
17Uloga varchar(50) not null,
18Korisnicko_ime varchar(150) primary key,
19
20constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Najava (Korisnicko_ime)
21);
22
23create table Administrator (
24Id_administrator serial not null,
25Korisnicko_ime varchar(150) primary key,
26
27constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Najava (Korisnicko_ime)
28);
29
30create table Kontroler (
31Id_kontroler serial not null,
32Korisnicko_ime varchar(150) primary key,
33
34constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Najava (Korisnicko_ime)
35);
36
37create table Kancelar (
38Id_kancelar serial not null,
39Korisnicko_ime varchar(150) primary key,
40
41constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Najava (Korisnicko_ime)
42);
43
44create table Ime_na_parking (
45Id_ime integer primary key,
46Lokacija varchar(150) not null,
47Administrator_Korisnicko_ime varchar(150) not null,
48
49constraint fk_Administrator_Korisnicko_ime foreign key (Administrator_Korisnicko_ime) references Administrator (Korisnicko_ime)
50);
51
52create table Zona (
53Id_zona varchar (20) primary key,
54Ime_na_parking_Id_Ime integer not null,
55
56constraint fk_Ime_na_parking foreign key (Ime_na_parking_Id_Ime) references Ime_na_parking (Id_ime)
57);
58
59create table Parking_mesto (
60Broj_na_pmesta integer primary key,
61IdZona varchar(20) not null,
62
63constraint fk_IdZona foreign key (IdZona) references Zona (Id_zona)
64);
65
66create table Korisnik(
67Id_korisnik serial not null,
68Korisnicko_ime varchar(150) primary key,
69
70constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Najava (Korisnicko_ime)
71);
72
73create table Avtomobil(
74Reg_tablica varchar(10) primary key,
75Marka varchar(20) not null,
76Boja varchar (15),
77Korisnickoime varchar(150) not null,
78
79constraint fk_Korisnickoime foreign key (Korisnickoime) references Korisnik (Korisnicko_ime)
80);
81
82
83create table Plakjanje (
84Id_plakanje integer primary key,
85Korisnickoime varchar(150) not null,
86Br_tel varchar(30),
87Br_na_smetka varchar(150),
88Tip_plakjanje varchar(150) not null,
89
90constraint fk_Korisnickoime foreign key (Korisnickoime) references Korisnik (Korisnicko_ime),
91constraint ck_tip_plakjanje check (case when tip_plakjanje='mobilno' then Br_tel!= 'not null' when tip_plakjanje='karticka' then Br_na_smetka!= 'not null' end)
92);
93
94
95create table Kazna (
96Id_kazna integer primary key,
97iznos integer not null,
98broj_kazni integer not null,
99Korisnickoime varchar(150) not null,
100
101constraint fk_Korisnickoime foreign key (Korisnickoime) references Korisnik (Korisnicko_ime)
102
103);
104
105create table Rezervacija (
106
107Id_rezervacija integer primary key,
108pocetno_vreme TIMESTAMP not null,
109krajno_vreme TIMESTAMP not null,
110Reg_tablica varchar(10) not null,
111Broj_na_pmesta integer not null,
112Id_plakanje integer not null ,
113
114constraint fk_Reg_tablica foreign key (Reg_tablica) references Avtomobil (Reg_tablica),
115constraint fk_Broj_na_pmesta foreign key (Broj_na_pmesta) references Parking_mesto (Broj_na_pmesta),
116constraint fk_Id_plakanje foreign key (Id_plakanje) references Plakjanje (Id_plakanje)
117);
118
119create table Kontrola (
120Id_kontrola serial primary key,
121izvrsena_kontrola integer not null,
122vreme_na_kontrola TIMESTAMP not null,
123konstantacija varchar(300) not null,
124Korisnicko_ime varchar(150) not null,
125Broj_na_pmesta integer not null,
126Id_rezervacija integer not null,
127Id_kazna integer not null,
128
129constraint fk_Korisnicko_ime foreign key (Korisnicko_ime) references Kontroler (Korisnicko_ime),
130constraint fk_Broj_na_pmesta foreign key (Broj_na_pmesta) references Parking_mesto (Broj_na_pmesta),
131constraint fk_Id_rezervacija foreign key (Id_rezervacija) references Rezervacija (Id_rezervacija),
132constraint fk_Id_kazna foreign key (Id_kazna) references Kazna (Id_kazna)
133);
Note: See TracBrowser for help on using the repository browser.