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