DDL: kreiranje.sql

File kreiranje.sql, 2.8 KB (added by 215010, 13 days ago)
Line 
1drop table if exists Service;
2drop table if exists Payment;
3drop table if exists Reservation;
4drop table if exists Room;
5drop table if exists Staff;
6drop table if exists Customer;
7drop table if exists Manager;
8drop table if exists Hotel_Building;
9drop table if exists Hotel_User;
10
11
12create table Hotel_User(
13 user_id bigint primary key,
14 first_name varchar(30) not null,
15 last_name varchar(30) not null,
16 phone varchar(9) not null,
17 email varchar(100) not null unique,
18 password varchar(100) not null
19);
20
21
22create table Staff(
23 user_id bigint primary key,
24 constraint staff_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
25);
26
27
28create table Customer(
29 user_id bigint primary key,
30 constraint customer_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
31);
32
33
34create table Manager(
35 user_id bigint primary key,
36 constraint manager_fk foreign key (user_id) references Hotel_User(user_id) on delete cascade
37);
38
39create table Hotel_Building(
40 building_id varchar(10) primary key,
41 address varchar(50) not null,
42 city varchar(20) not null,
43 floor integer not null,
44 num_rooms integer not null
45);
46
47
48create table Room(
49 room_number integer,
50 room_type varchar(20) not null,
51 number_of_beds integer not null,
52 price_per_night bigint not null,
53 available boolean not null,
54 building_id varchar(10),
55 constraint room_pkey primary key (room_number, building_id),
56 constraint room_fk foreign key (building_id) references Hotel_Building(building_id)
57);
58
59create table Reservation(
60 reservation_id bigint primary key,
61 start_date date not null,
62 end_date date,
63 status varchar(40) not null,
64 reserv_date date not null,
65 room_number integer,
66 building_id varchar(10),
67 customer_id bigint,
68 manager_id bigint,
69 constraint reservation_fk_room foreign key(room_number, building_id) references Room(room_number, building_id),
70 constraint reservation_fk_customer foreign key(customer_id) references Customer(user_id),
71 constraint reservation_fk_manager foreign key(manager_id) references Manager(user_id)
72);
73
74create table Payment(
75 p_id bigint primary key,
76 p_method varchar(5) not null,
77 amount integer not null,
78 p_date date not null,
79 customer_id bigint,
80 reservation_id bigint,
81 constraint payment_fk_reservation foreign key (reservation_id) references Reservation(reservation_id),
82 constraint payment_fk foreign key (customer_id) references Customer(user_id)
83);
84
85
86create table Service(
87 service_id bigint primary key,
88 service_type varchar(40) not null,
89 service_date date,
90 service_status varchar(70) not null,
91 room_number integer,
92 building_id varchar(10),
93 staff_id bigint,
94 CONSTRAINT service_fk_room FOREIGN KEY (room_number, building_id) REFERENCES Room(room_number, building_id),
95 CONSTRAINT service_fk_staff FOREIGN KEY (staff_id) REFERENCES Staff(user_id)
96);