RelationalDesign: kreiranje.sql

File kreiranje.sql, 3.5 KB (added by 193014, 2 years ago)
Line 
1drop schema if exists project cascade;
2create schema project;
3
4drop table if exists REZERVACIJA_USLUGI;
5drop table if exists VRABOTENI_USLUGI;
6drop table if exists TERMIN;
7drop table if exists REZERVACIJA;
8drop table if exists BEAUTYCENTER;
9drop table if exists UPLATA;
10drop table if exists OCENA;
11drop table if exists USLUGI;
12drop table if exists KLIENTI;
13drop table if exists VRABOTENI;
14drop table if exists USERS;
15
16
17create table USERS(
18 User_ID serial primary key,
19 Username varchar(100) not null unique,
20 UPassword varchar(100) not null
21);
22
23create table KLIENTI(
24 User_ID integer primary key,
25 Ime varchar(100) not null,
26 Prezime varchar(100),
27 Tel_br varchar(12) not null,
28 E_mail varchar(150),
29
30 constraint fk_User_ID_klient foreign key (User_ID) references users(User_ID)
31);
32
33create table BEAUTYCENTER(
34 Salon_ID varchar(100) primary key,
35 Adresa varchar(100) not null,
36 Tel_br varchar(12) not null,
37 E_mail varchar(100)
38);
39
40create table VRABOTENI(
41 User_ID integer primary key,
42 First_name varchar(100) not null,
43 Middle_name varchar(100),
44 Prezime varchar(100),
45 E_mail varchar(100) not null,
46 Tel_br varchar(12),
47 Rab_iskustvo integer,
48 Salon_ID varchar(100) not null,
49 raboti_od timestamp not null,
50 raboti_do timestamp,
51
52 constraint fk_Salon_ID foreign key (Salon_ID) references beautycenter(Salon_ID) ,
53 constraint fk_User_ID_vraboten foreign key (User_ID) references users(User_ID)
54);
55
56create table UPLATA(
57 Uplata_ID serial primary key,
58 Informacii varchar(100)
59);
60create table TERMINI(
61 Termin_ID serial primary key,
62 Pocetok timestamp not null,
63 Vremetraenje integer,
64 User_ID_vraboten integer not null,
65
66 constraint fk_User_ID_vraboten foreign key (User_ID_vraboten) references vraboteni(User_ID)
67);
68
69create table REZERVACIJA(
70 Br_rez serial primary key,
71 User_ID_klient integer not null,
72 Termin_ID integer not null,
73 Uplata_ID integer,
74 User_ID_vraboten integer,
75
76
77 constraint fk_User_ID_klient foreign key (User_ID_klient) references klienti(User_ID),
78 constraint fk_Termin_ID foreign key (Termin_ID) references termini(Termin_ID),
79 constraint fk_Uplata_ID foreign key (Uplata_ID) references uplata(Uplata_ID),
80 constraint fk_User_ID_vraboten foreign key (User_ID_vraboten) references vraboteni(User_ID)
81
82);
83
84create table USLUGI(
85 Usluga_ID varchar(100) primary key,
86 Dejnost varchar(100),
87 Cena varchar(100) not null
88);
89
90create table OCENA(
91 Ocena_ID serial primary key,
92 Vrednost integer not null,
93 Komentar varchar(200),
94 User_ID_klient integer not null,
95 Usluga_ID varchar(100) not null,
96 br_rez integer,
97
98
99 constraint fk_User_ID_klient foreign key (User_ID_klient) references klienti(User_ID),
100 constraint fk_Usluga_ID foreign key (Usluga_ID) references uslugi(Usluga_ID),
101 constraint fk_Br_rez foreign key (br_rez) references rezervacija(br_rez)
102);
103
104create table REZERVACIJA_USLUGI(
105 Br_rez integer not null,
106 Usluga_ID varchar(100) not null,
107
108 constraint pk_rezervacija_uslugi primary key (Br_rez, Usluga_ID),
109 constraint fk_Br_rez foreign key (br_rez) references rezervacija(br_rez),
110 constraint fk_Usluga_ID foreign key (Usluga_ID) references uslugi(Usluga_ID)
111);
112
113create table VRABOTENI_USLUGI(
114 User_ID_vraboten integer not null,
115 Usluga_ID varchar(100) not null,
116
117 constraint pk_vraboteni_uslugi primary key (User_ID_vraboten, Usluga_ID),
118 constraint fk_User_ID_vraboten foreign key (User_ID_vraboten) references vraboteni(User_ID),
119 constraint fk_Usluga_ID foreign key (Usluga_ID) references uslugi(Usluga_ID)
120);
121
122
123