1 | drop schema if exists project cascade;
|
---|
2 | create schema project;
|
---|
3 |
|
---|
4 | drop table if exists Rezervacija;
|
---|
5 | drop table if exists Ocenka;
|
---|
6 | drop table if exists Tip;
|
---|
7 | drop table if exists Klient cascade;
|
---|
8 | drop table if exists Termin;
|
---|
9 |
|
---|
10 | drop table if exists Trening;
|
---|
11 | drop table if exists Fitnes_Centar cascade;
|
---|
12 | drop table if exists Fitnes_Instruktor;
|
---|
13 | drop table if exists Sopstvenik;
|
---|
14 | drop table if exists Korisnici cascade;
|
---|
15 |
|
---|
16 | create table Korisnici (
|
---|
17 | user_id int primary key,
|
---|
18 | username varchar(100) not null unique,
|
---|
19 | uloga varchar(20),
|
---|
20 | password varchar(100) not null
|
---|
21 | );
|
---|
22 |
|
---|
23 | create table Fitnes_Centar (
|
---|
24 | id int primary key,
|
---|
25 | id_sopstv int,
|
---|
26 | ime varchar(100) not null,
|
---|
27 | tel_br varchar(15),
|
---|
28 | lokacija varchar(150)
|
---|
29 |
|
---|
30 | );
|
---|
31 |
|
---|
32 | create table Klient (
|
---|
33 | user_id_klient int primary key,
|
---|
34 | ime varchar(50) not null,
|
---|
35 | prezime varchar(50) not null,
|
---|
36 | email varchar(100) unique not null,
|
---|
37 | tel_broj varchar(15),
|
---|
38 | constraint fk20 foreign key (user_id_klient) references Korisnici(user_id)
|
---|
39 | );
|
---|
40 |
|
---|
41 | create table Sopstvenik (
|
---|
42 | user_id_sopstvenik int primary key,
|
---|
43 | id_gym int,
|
---|
44 | username varchar(30),
|
---|
45 | ime varchar(100) not null,
|
---|
46 | prezime varchar(100) not null,
|
---|
47 | tel_br varchar(15),
|
---|
48 | email varchar(150),
|
---|
49 | constraint fk1 foreign key (user_id_sopstvenik) references Korisnici(user_id),
|
---|
50 | constraint ff foreign key (id_gym) references Fitnes_Centar(id)
|
---|
51 | );
|
---|
52 |
|
---|
53 | create table Fitnes_Instruktor (
|
---|
54 | user_id_instruktor int primary key,
|
---|
55 | ime varchar(100) not null,
|
---|
56 | prezime varchar(100) not null,
|
---|
57 | kratka_bio text,
|
---|
58 | rab_iskustvo int,
|
---|
59 | tel_broj varchar(15),
|
---|
60 | email varchar(150),
|
---|
61 | constraint fk2 foreign key (user_id_instruktor) references Korisnici(user_id)
|
---|
62 | );
|
---|
63 |
|
---|
64 | create table Trening (
|
---|
65 | trening_id int primary key,
|
---|
66 | tip varchar(50) not null,
|
---|
67 | user_id_instruktor_trening int not null,
|
---|
68 | constraint fk4 foreign key (user_id_instruktor_trening) references Fitnes_Instruktor(user_id_instruktor)
|
---|
69 | );
|
---|
70 |
|
---|
71 | create table Tip (
|
---|
72 | trening_id_tip int primary key,
|
---|
73 | individualen varchar(20) not null,
|
---|
74 | grupen varchar(20) not null,
|
---|
75 | constraint fk5 foreign key (trening_id_tip) references Trening(trening_id)
|
---|
76 | );
|
---|
77 |
|
---|
78 | create table Termin (
|
---|
79 | termin_id int,
|
---|
80 | trening_id_termin int not null,
|
---|
81 | user_id_klient_termin int,
|
---|
82 | pocetok timestamp not null,
|
---|
83 | vremetraenje int,
|
---|
84 | primary key (termin_id, trening_id_termin, user_id_klient_termin),
|
---|
85 | constraint fk6 foreign key (trening_id_termin) references Trening(trening_id),
|
---|
86 | constraint fk7 foreign key (user_id_klient_termin) references Klient(user_id_klient)
|
---|
87 | );
|
---|
88 |
|
---|
89 | create table Rezervacija (
|
---|
90 | termin_id int not null,
|
---|
91 | trening_id_rez int not null,
|
---|
92 | user_id_klient_rez int not null,
|
---|
93 | primary key (termin_id, trening_id_rez, user_id_klient_rez),
|
---|
94 | constraint fk10 foreign key (termin_id, trening_id_rez, user_id_klient_rez) references Termin(termin_id, trening_id_termin, user_id_klient_termin)
|
---|
95 | );
|
---|
96 |
|
---|
97 | create table Ocenka (
|
---|
98 | trening_id_o int not null,
|
---|
99 | user_id_klient_o int not null,
|
---|
100 | vrednost int not null,
|
---|
101 | komentar text,
|
---|
102 | primary key(trening_id_o, user_id_klient_o),
|
---|
103 | constraint fk11 foreign key (trening_id_o) references Trening(trening_id),
|
---|
104 | constraint fk12 foreign key (user_id_klient_o) references Klient(user_id_klient)
|
---|
105 | );
|
---|