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