Repository navigation
Expand file tree
/
Copy pathHotelDataBase.sql
More file actions
226 lines (184 loc) · 6.55 KB
/
Copy pathHotelDataBase.sql
File metadata and controls
226 lines (184 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
DROP DATABASE IF EXISTS HOTEL_COMP333;
CREATE DATABASE HOTEL_COMP333;
USE HOTEL_COMP333;
create table employee (
eid int primary key AUTO_INCREMENT, -- 1000 , 1001,1002,1003
employee_SSN int UNIQUE,
employee_first_Name varchar(32),
employee_father_Name varchar(32),
employee_family_Name varchar(32),
employee_email varchar(32),
employee_nationality varchar(32),
starting_date DATE DEFAULT(CURRENT_DATE()) ,
salary real,
password VARCHAR(32) NOT NULL
);
ALTER TABLE employee AUTO_INCREMENT = 1000;
create table service(
service_id int primary key AUTO_INCREMENT,
service_type varchar(32),
service_price real DEFAULT 0.00
-- serving_date_time DATETIME DEFAULT NOW() WILL BE MOVED TO SERVICE_TO_ROOM TABLE
);
create table Guest(
Guest_SSN int primary key,
Guest_first_Name varchar(32),
Guest_father_Name varchar(32),
Guest_family_Name varchar(32),
Guest_email varchar(32),
Guest_nationality varchar(32),
phone_num VARCHAR(32) -- ONE VALUE
-- phone is multivalued so it's a table by itself
);
CREATE TABLE employee_phone(
phone_num VARCHAR(32) ,
eid INT,
PRIMARY KEY(phone_num,eid),
FOREIGN KEY(eid) REFERENCES EMPLOYEE(eid)
);
create table room (
room_number int primary key,
room_price real,
number_of_beds INT,
room_type VARCHAR(32),
room_status VARCHAR(32) -- OCCUPIED OR NOT
);
create table service_to_room( -- SAME AS 'PROVIDE'
-- suggestion : provides service to a room not a guest
room_number int,
eid int,
service_id int,
isPaid bool DEFAULT(FALSE),
service_date DATE DEFAULT ( current_date()),
primary key (room_number, eid, service_id),
foreign key (room_number) references room (room_number),
foreign key (eid) references employee (eid),
foreign key (service_id) references service(service_id)
);
create table Booking(
Booking_id int primary key AUTO_INCREMENT,
room_number INT,
guest_ssn INT,
STARTING_DATE date,
end_date date,
FOREIGN KEY(room_number) REFERENCES room (room_number),
FOREIGN KEY(guest_ssn) REFERENCES guest (guest_ssn)
);
CREATE TABLE PAYMENT(
Payment_id INT PRIMARY KEY AUTO_INCREMENT,
Payment_way varchar(32),
Payment_Date DATE,
Guest_SSN int not null,
amountPaid double,
foreign key (Guest_SSN) references Guest (Guest_SSN)
);
alter table booking auto_increment =1;
-- DEFAULT INSERTIONS:
-- EMP TABLE:
INSERT INTO EMPLOYEE (employee_SSN, employee_first_Name, employee_father_Name, employee_family_Name,
employee_email, employee_nationality, salary, password)
VALUES (1, 'root', 'root', 'root', 'root@gmail.com', 'PS', 999.9, 'password');
INSERT INTO EMPLOYEE (employee_SSN, employee_first_Name, employee_father_Name, employee_family_Name,
employee_email, employee_nationality, salary, password)
VALUES (2, 'Faris', 'Amer', 'Abufarha', 'farisabufarha33@gmail.com', 'PS', 1299.9, 'faris');
INSERT INTO EMPLOYEE (employee_SSN, employee_first_Name, employee_father_Name, employee_family_Name,
employee_email, employee_nationality, salary, password)
VALUES (3, 'Saja', 'Musheer', 'Shareef', 'saja@gmail.com', 'PS', 999.9, 'saja');
INSERT INTO EMPLOYEE (employee_SSN, employee_first_Name, employee_father_Name, employee_family_Name,
employee_email, employee_nationality, salary, password)
VALUES (4, 'Shereen', 'Khaled', 'Ibdah', 'shereen@gmail.com', 'PS', 999.9, 'shereen');
INSERT INTO EMPLOYEE (employee_SSN, employee_first_Name, employee_father_Name, employee_family_Name,
employee_email, employee_nationality, salary, password)
VALUES (5, 'Hamza', 'hamza father', 'Awashra', 'hamza@gmail.com', 'PS', 999.9, 'hamza');
-- ROOM table
INSERT INTO room
VALUES (101, 99.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (102, 99.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (103, 99.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (104, 99.9, 2, 'sweet', 'FREE');
-- SECOND FLOOR
INSERT INTO room
VALUES (201, 199.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (202, 199.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (203, 199.9, 2, 'sweet', 'FREE');
INSERT INTO room
VALUES (204, 199.9, 2, 'sweet', 'FREE');
-- 3RD
INSERT INTO room
VALUES (301, 170.9, 1, 'single', 'FREE');
INSERT INTO room
VALUES (302, 170.9, 1, 'single', 'FREE');
INSERT INTO room
VALUES (303, 170.9, 1, 'single', 'FREE');
INSERT INTO room
VALUES (304, 170.9, 1, 'single', 'FREE');
-- PHONES
INSERT INTO employee_phone (eid, phone_num)
VALUES (1001, '0595110186');
INSERT INTO employee_phone (eid, phone_num)
VALUES (1001, '0569157426');
-- services GUESS SHOULD BE CHANGED
INSERT INTO service (service_type, service_price)
VALUES ('Cleaning', 0);
-- INSERTIONS TO SERVICE TO ROOM TABLE
INSERT INTO service_to_room (room_number, eid, service_id)
VALUES (101, 1000, 1);
insert INTO Guest (guest_ssn,Guest_first_Name,Guest_family_Name,Guest_father_Name,Guest_email,Guest_nationality,phone_num)
values (12345,'ramez','yazeed','ibdah','ahmad@gmail.com','PS','0599274443'),
(1283,'amro','ahmad','saif','amro@gmail.com','PS','0598378134') ,
(1344,'narmeen','ibdah','ibdah','narmeen@gmail.com','PS','0259390233'),
(1256,'tala' , 'mosheer' , 'sharif', 'tala@outlook.com','ps','0596349522'),
(1239,'mohammed','sh','husni','moh@gmail.com','ps','0599293678'),
(1033,'ahmed','mohammed','hasan','ahmad@gmail.com','ps','0599929359');
insert into Booking (room_number,guest_ssn,Starting_date , end_date)
values (301,1256,'2023-1-1','2023-1-3'),
(303,1344,'2022-2-9','2022-2-19'),
(302,1239,'2023-1-1','2023-1-3'),
(301,1239,'2023-1-1','2023-1-3'),
(202,1033,'2023-1-1','2023-1-3'),
(204,1344,'2023-1-1','2023-1-3')
;
select * from Guest;
select * from booking;
--
#Name of all guest who book room number 301
select G.Guest_first_Name
From guest G , booking B
where G.Guest_SSN = B.guest_ssn
and B.room_number = 301;
--
select b.Booking_id
from guest g , Booking b
where g.Guest_nationality = 'ps' and
g.Guest_SSN = b.Guest_SSN;
--
select b.Booking_id
from guest g , Booking b
where g.Guest_first_Name = 'mohammed' and
g.Guest_SSN = b.Guest_SSN;
-- name of guest how reserved room 302 and 301
select G.Guest_first_Name
from Guest G , booking B
where G.Guest_SSN = B.guest_ssn
and B.room_number = 302 and G.guest_ssn IN(
select B.guest_ssn
from booking B
where B.room_number = 301
);
#find name all guest who is room_type = "sweet"
select g.Guest_first_Name
from guest g ,Booking b , room r
where b.room_number = r.room_number and b.guest_ssn = g.guest_ssn
and r.room_type = 'sweet';
-- the employee with max salary
select employee.employee_first_Name
from employee
where employee.salary = (
select max(employee.salary)
from employee
);