├── ERR Diagram ├── ERR.PNG ├── The ER Sketch.jpeg └── hotel_database.mwb ├── SwetaGupta-VaibhaviMore-TaskTracker.xlsx ├── Documentation & Presentation ├── Presentation.pptx ├── ~$Presentation.pptx └── Hotel Database Management System-SwetaGupta.pdf ├── SQL Queries & Triggers & Views ├── Trigger on delete.PNG ├── Query8.sql ├── Query3.sql ├── Query4.sql ├── Query6.sql ├── Query5.sql ├── Query1.sql ├── Query2.sql ├── Query7.sql ├── employeeDetails_view.sql ├── guestDetails_view.sql ├── Query9.sql ├── BookingAudit_OnDeleteTrigger.sql ├── BookingAudit_Trigger.sql ├── queries.sql ├── insert_data.sql └── create_hotel_database.sql └── README.md /ERR Diagram/ERR.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/ERR Diagram/ERR.PNG -------------------------------------------------------------------------------- /ERR Diagram/The ER Sketch.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/ERR Diagram/The ER Sketch.jpeg -------------------------------------------------------------------------------- /ERR Diagram/hotel_database.mwb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/ERR Diagram/hotel_database.mwb -------------------------------------------------------------------------------- /SwetaGupta-VaibhaviMore-TaskTracker.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/SwetaGupta-VaibhaviMore-TaskTracker.xlsx -------------------------------------------------------------------------------- /Documentation & Presentation/Presentation.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/Documentation & Presentation/Presentation.pptx -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Trigger on delete.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/SQL Queries & Triggers & Views/Trigger on delete.PNG -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query8.sql: -------------------------------------------------------------------------------- 1 | -- List all the hotels that have a URL available. 2 | SELECT * 3 | FROM `hotel` 4 | WHERE hotel_website IS NOT NULL; -- get the hotels whose URL is not null -------------------------------------------------------------------------------- /Documentation & Presentation/~$Presentation.pptx: -------------------------------------------------------------------------------- 1 | User User -------------------------------------------------------------------------------- /Documentation & Presentation/Hotel Database Management System-SwetaGupta.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swetababu/HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT/HEAD/Documentation & Presentation/Hotel Database Management System-SwetaGupta.pdf -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query3.sql: -------------------------------------------------------------------------------- 1 | -- How many hotels are in a hotel chain? 2 | SELECT count(*) AS 'Total Hotels' -- count of total hotels 3 | FROM hotel_chain_has_hotel 4 | WHERE hotel_chains_hotel_chain_id = 1; -- for hotel chain 'best western hotels' -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query4.sql: -------------------------------------------------------------------------------- 1 | -- How many books has a customer made in one year? 2 | SELECT count(*) AS 'Total Bookings' -- count of total bookings 3 | FROM bookings 4 | WHERE YEAR(booking_date) = 2018 AND guests_guest_id = 1; -- bookings in Year 2018 by guest Jane with id 1 -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query6.sql: -------------------------------------------------------------------------------- 1 | -- List all the unique countries hotels are located in. 2 | SELECT DISTINCT country -- unique countries 3 | FROM addresses 4 | WHERE address_id IN -- compare to get addresses of hotels 5 | ( SELECT addresses_address_id -- address id of hotels 6 | FROM hotel); -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query5.sql: -------------------------------------------------------------------------------- 1 | -- How many rooms are booked in a particular hotel on a given date? 2 | SELECT SUM(total_rooms_booked) AS 'Total Rooms Booked' -- sum of total rooms 3 | FROM `bookings` 4 | WHERE booking_date LIKE '2018-06-08%' AND hotel_hotel_id = 1; -- for date 6th August,2018; and for hotel(King George Inn & Suites) with id 1 -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query1.sql: -------------------------------------------------------------------------------- 1 | -- How many distinct guest have made bookings for a particular month? 2 | SELECT guest_first_name, guest_last_name,guest_contact_number 3 | FROM guests 4 | WHERE guest_id IN 5 | ( SELECT distinct guests_guest_id -- get distinct guests 6 | FROM bookings 7 | WHERE MONTH(check_in_date) = 8); -- bookings for the month of August -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query2.sql: -------------------------------------------------------------------------------- 1 | -- How many distinct guest have made bookings for a particular month? 2 | SELECT guest_first_name, guest_last_name,guest_contact_number 3 | FROM guests 4 | WHERE guest_id IN 5 | ( SELECT distinct guests_guest_id -- get distinct guests 6 | FROM bookings 7 | WHERE MONTH(check_in_date) = 8); -- bookings for the month of August -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query7.sql: -------------------------------------------------------------------------------- 1 | -- How many rooms are available in a given hotel? 2 | SELECT h.hotel_room_capacity - SUM(b.total_rooms_booked) AS 'Available Rooms' -- get available rooms 3 | FROM `bookings` b JOIN hotel h 4 | ON b.hotel_hotel_id = h.hotel_id 5 | WHERE booking_date LIKE '2018-06-08%' AND hotel_hotel_id = 1 -- for given date and for hotel(King George Inn & Suites) with id 1 -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/employeeDetails_view.sql: -------------------------------------------------------------------------------- 1 | -- create view named hotel_employees to get details of all the employees 2 | CREATE OR REPLACE VIEW hotel_employees AS 3 | SELECT emp_first_name AS 'First Name', emp_last_name AS 'Last Name', emp_email_address AS 'Email Address', emp_contact_number AS 'Contact Number', department_name AS 'Department' 4 | FROM employees 5 | JOIN department 6 | ON department.department_id = employees.department_department_id; 7 | 8 | -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/guestDetails_view.sql: -------------------------------------------------------------------------------- 1 | -- create view named hotel_guests to get details of the guests 2 | CREATE OR REPLACE VIEW hotel_guests AS 3 | SELECT guest_first_name AS 'First Name', guest_last_name AS 'Last Name', guest_email_address AS 'Email Address', guest_contact_number AS 'Contact Number',country,state,zipcode 4 | FROM guests 5 | JOIN addresses ON addresses.address_id = guests.addresses_address_id 6 | WHERE guests.guest_id IN 7 | (SELECT distinct guests_guest_id -- get distinct guests 8 | FROM bookings 9 | WHERE hotel_hotel_id = 1); -- for hotel(King George Inn & Suites) with id 1 10 | 11 | -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/Query9.sql: -------------------------------------------------------------------------------- 1 | -- List the rate for a room at a given time during the year. 2 | SELECT ROUND((r_type.room_cost - ((r_dis.discount_rate * r_type.room_cost)/100)), 2) AS 'Room Rate' -- get room price on the basis od discount 3 | FROM room_rate_discount r_dis JOIN room_type r_type -- join rate discount table with room type 4 | ON r_dis.room_type_room_type_id = r_type.room_type_id 5 | WHERE r_type.room_type_id 6 | IN ( Select rooms_type_rooms_type_id from rooms where room_id = 1) -- get room type id for room with id 1 7 | AND MONTH(NOW()) BETWEEN r_dis.start_month AND r_dis.end_month; -- get discount rate for current month -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/BookingAudit_OnDeleteTrigger.sql: -------------------------------------------------------------------------------- 1 | USE hotel_database; 2 | 3 | SET sql_notes = 0; -- Temporarily disable the "Table already exists" warning 4 | 5 | -- create table for bookings audit 6 | CREATE TABLE IF NOT EXISTS hotel_database.Bookings_Audit( 7 | 8 | audit_id int NOT NULL PRIMARY KEY AUTO_INCREMENT, 9 | `booking_id` INT NOT NULL, 10 | `booking_date` DATETIME NULL, 11 | `duration_of_stay` VARCHAR(10) NULL, 12 | `check_in_date` DATETIME NULL, 13 | `check_out_date` DATETIME NULL, 14 | `booking_payment_type` VARCHAR(45) NULL, 15 | `total_rooms_booked` INT NULL, 16 | `hotel_hotel_id` INT NOT NULL, 17 | `guests_guest_id` INT NOT NULL, 18 | `employees_emp_id` INT NOT NULL, 19 | `total_amount` DECIMAL(10,2) NULL, 20 | action_type varchar(50) NOT NULL, 21 | date_updated datetime NOT NULL 22 | ); 23 | 24 | DROP TRIGGER IF EXISTS bookings_after_delete; 25 | 26 | DELIMITER // 27 | 28 | CREATE TRIGGER bookings_after_delete 29 | AFTER DELETE ON bookings 30 | FOR EACH ROW 31 | 32 | BEGIN 33 | INSERT INTO Bookings_Audit VALUES 34 | (NULL, OLD.booking_id, OLD.booking_date, OLD.duration_of_stay, OLD.`check_in_date`, OLD.`check_out_date`, OLD.`booking_payment_type`, OLD.`total_rooms_booked`, OLD.`hotel_hotel_id`, OLD.`guests_guest_id`, OLD.`employees_emp_id`, OLD.`total_amount`,"DELETED", NOW()); 35 | END// 36 | 37 | DELIMITER ; 38 | 39 | SET sql_notes = 1; -- And then re-enable the warning again 40 | -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/BookingAudit_Trigger.sql: -------------------------------------------------------------------------------- 1 | USE hotel_database; 2 | 3 | SET sql_notes = 0; -- Temporarily disable the "Table already exists" warning 4 | 5 | -- create table for bookings audit 6 | CREATE TABLE IF NOT EXISTS hotel_database.Bookings_Audit( 7 | audit_id int NOT NULL PRIMARY KEY AUTO_INCREMENT, 8 | `booking_id` INT NOT NULL, 9 | `booking_date` DATETIME NULL, 10 | `duration_of_stay` VARCHAR(10) NULL, 11 | `check_in_date` DATETIME NULL, 12 | `check_out_date` DATETIME NULL, 13 | `booking_payment_type` VARCHAR(45) NULL, 14 | `total_rooms_booked` INT NULL, 15 | `hotel_hotel_id` INT NOT NULL, 16 | `guests_guest_id` INT NOT NULL, 17 | `employees_emp_id` INT NOT NULL, 18 | `total_amount` DECIMAL(10,2) NULL, 19 | action_type varchar(50) NOT NULL, 20 | date_updated datetime NOT NULL 21 | ); 22 | 23 | 24 | DROP TRIGGER IF EXISTS bookings_after_insert; 25 | 26 | DELIMITER // 27 | 28 | CREATE TRIGGER bookings_after_insert 29 | AFTER INSERT ON bookings 30 | FOR EACH ROW 31 | 32 | BEGIN 33 | INSERT INTO Bookings_Audit VALUES 34 | (NEW.booking_id, NEW.booking_date, NEW.duration_of_stay, NEW.`check_in_date`, NEW.`check_out_date`, NEW.`booking_payment_type`, NEW.`total_rooms_booked`, NEW.`hotel_hotel_id`, NEW.`guests_guest_id`, NEW.`employees_emp_id`, NEW.`total_amount`,"INSERTED", NOW()); 35 | END// 36 | 37 | DELIMITER ; 38 | 39 | 40 | SET sql_notes = 1; -- And then re-enable the warning again 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HOTEL-MANAGEMENT-SYSTEM-DATABASE-PROJECT 2 | 3 | # Details 4 | 5 | A hotel is a hive of numerous operations such as front office, booking, and reservation, inventory, material management, quality management, security, energy management, housekeeping, CRM and more. 6 | 7 | 8 | A hotel can be apart of different Hotel Chains. A hotel chain my have multiple hotels. A hotel has multiple rooms and floors, and these rooms can be of different types. By room type, each room has the different price and description. 9 | A hotel has some employees to manage the services provided to customers. The customer can book the room either online or by cash payment at the hotel. 10 | 11 | 12 | The guest record is stored in hotel database which contains customer identity, his address, check in time, check out time, etc. 13 | 14 | # Hotel info should include: 15 | 16 | Countries 17 | 18 | Hotel Chain Name 19 | 20 | Hotel Name 21 | 22 | Hotel URL 23 | 24 | Hotel Characteristics (Description) 25 | 26 | A Hotel must have one and only one STAR_RATING 27 | 28 | Each star rating has an image 29 | 30 | A Hotel has a ROOM CAPACITY and FLOOR COUNT 31 | 32 | A Hotel can have one and only one ADDRESS. 33 | 34 | # Other hotel requirements: 35 | 36 | Track guests based on their name, address, city 37 | 38 | Track bookings based on dates, booking type, and room count 39 | 40 | Designate Room Types with a standard rate, room description, and if smoking is allowed 41 | 42 | There will be room rate periods to give discounts at various times of the year (e.g. Jan to March, July to Aug, Sept to Dec) 43 | 44 | # Queries that will be required: 45 | 46 | How many distinct guest have made bookings for a particular month? 47 | 48 | How many available rooms are in a particular hotel for a given date? 49 | 50 | How many hotels are in a hotel chain? 51 | 52 | How many books has a customer made in one year? 53 | 54 | How many rooms are booked in a particular hotel on a given date? 55 | 56 | List all the unique countries hotels are located in. 57 | 58 | How many rooms are available in a given hotel? 59 | 60 | List all the hotels that have a URL available. 61 | 62 | List the rate for a room at a given time during the year. 63 | 64 | # Additional Requirements: 65 | 66 | Work in groups of 2 or 3 to complete the work order 67 | 68 | Each team member must track their work and submit with their final project files (Use the included time-tracker.xlsx file) 69 | 70 | Each team member must submit a table breakdown in written form for at least 2 tables in the database. These tables must be unique from the other members in your group. 71 | 72 | Work in teams to determine the tables and relationships required 73 | 74 | Database must be normalized to 3rd normal form 75 | 76 | Create an EER Model of the completed database structure (Image file is acceptable) 77 | 78 | Make sure to include primary/foreign keys where appropriate 79 | 80 | Review the attached work log for additional views/functions required 81 | 82 | -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/queries.sql: -------------------------------------------------------------------------------- 1 | -- How many distinct guest have made bookings for a particular month? 2 | SELECT guest_first_name, guest_last_name,guest_contact_number 3 | FROM guests 4 | WHERE guest_id IN 5 | ( SELECT distinct guests_guest_id -- get distinct guests 6 | FROM bookings 7 | WHERE MONTH(check_in_date) = 8); -- bookings for the month of August 8 | 9 | -- How many available rooms are in a particular hotel for a given date? 10 | SELECT h.hotel_room_capacity AS 'Total Rooms', SUM(total_rooms_booked) AS 'Total Rooms Booked' , h.hotel_room_capacity - SUM(b.total_rooms_booked) AS 'Available Rooms' -- get available rooms 11 | FROM `bookings` b JOIN hotel h 12 | ON b.hotel_hotel_id = h.hotel_id 13 | WHERE booking_date LIKE '2018-08-14%' AND hotel_hotel_id = 1 -- for given date and for hotel(King George Inn & Suites) with id 1 14 | 15 | -- How many hotels are in a hotel chain? 16 | SELECT count(*) AS 'Total Hotels' -- count of total hotels 17 | FROM hotel_chain_has_hotel 18 | WHERE hotel_chains_hotel_chain_id = 1; -- for hotel chain 'best western hotels' 19 | 20 | -- How many books has a customer made in one year? 21 | SELECT count(*) AS 'Total Bookings' -- count of total bookings 22 | FROM bookings 23 | WHERE YEAR(booking_date) = 2018 AND guests_guest_id = 1; -- bookings in Year 2018 by guest Jane with id 1 24 | 25 | -- How many rooms are booked in a particular hotel on a given date? 26 | SELECT SUM(total_rooms_booked) AS 'Total Rooms Booked' -- sum of total rooms 27 | FROM `bookings` 28 | WHERE booking_date LIKE '2018-06-08%' AND hotel_hotel_id = 1; -- for date 6th August,2018; and for hotel(King George Inn & Suites) with id 1 29 | 30 | -- List all the unique countries hotels are located in. 31 | SELECT DISTINCT country -- unique countries 32 | FROM addresses 33 | WHERE address_id IN -- compare to get addresses of hotels 34 | ( SELECT addresses_address_id -- address id of hotels 35 | FROM hotel); 36 | 37 | 38 | -- How many rooms are available in a given hotel? 39 | SELECT h.hotel_room_capacity - SUM(b.total_rooms_booked) AS 'Available Rooms' -- get available rooms 40 | FROM `bookings` b JOIN hotel h 41 | ON b.hotel_hotel_id = h.hotel_id 42 | WHERE booking_date LIKE '2018-06-08%' AND hotel_hotel_id = 1 -- for given date and for hotel(King George Inn & Suites) with id 1 43 | 44 | -- List all the hotels that have a URL available. 45 | SELECT * 46 | FROM `hotel` 47 | WHERE hotel_website IS NOT NULL; -- get the hotels whose URL is not null 48 | 49 | -- List the rate for a room at a given time during the year. 50 | SELECT ROUND((r_type.room_cost - ((r_dis.discount_rate * r_type.room_cost)/100)), 2) AS 'Room Rate' -- get room price on the basis od discount 51 | FROM room_rate_discount r_dis JOIN room_type r_type -- join rate discount table with room type 52 | ON r_dis.room_type_room_type_id = r_type.room_type_id 53 | WHERE r_type.room_type_id 54 | IN ( Select rooms_type_rooms_type_id from rooms where room_id = 1) -- get room type id for room with id 1 55 | AND MONTH(NOW()) BETWEEN r_dis.start_month AND r_dis.end_month; -- get discount rate for current month 56 | 57 | -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/insert_data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `addresses`(`address_id`, `address_line1`, `address_line2`, `city`, `state`, `country`, `zipcode`) 2 | VALUES 3 | (1,49, 'Dave Street', 'Kitchener','ON','Canada','N2C 2P6'), 4 | (2,64, 'Victoria Street', 'Kitchener','ON','Canada','N2C 2M6'), 5 | (3,79, 'Connaught Street', 'London','ON','Canada','N2C 2K3'), 6 | (4,45, 'Sweden St. Street', 'London','ON','Canada','N2A 0E4'), 7 | (5,60, 'Lincoln Street', 'Guelph','ON','Canada','N2C 2E8'), 8 | (6,20400, 'Phoenix', NULL,'AZ','USA','AZ85027'), 9 | (7,8033, 'King George Boulevard', 'Surrey','BC','Canada','V3W 5B4'), 10 | (8,1565, 'E South St', 'Globe','AZ','USA','85501'), 11 | (9,32, ' Gandhi Road', 'Mumbai','Maharashtra','India','534076'), 12 | (10,706, 'Idle rd', 'Saskatoon','SK','Bangladesh','S2L 562'), 13 | (11,45, 'Vanier Park', 'Kitchener','ON','Canada','Sd3 d35'), 14 | (12,41, 'Greenfield', 'London','ON','Canada','234 987'), 15 | (13,89, 'Jacob Rd', 'Paris','ON','Canada','467 289'), 16 | (14,85, 'Martin Street', 'Ottawa','BC','Canada','263 987'), 17 | (15,78, 'Josseph St. Street', 'Guelph','BC','Canada','267 387'), 18 | (16,156, 'James Road', NULL,'AZ','USA','263 762'), 19 | (17,7598, 'Atomic Street', 'Ottawa','New York','USA','756 145'), 20 | (18,5476, 'Saint Jake Rd', 'NULL','San Jose','USA','675 846'), 21 | (19,7465, 'Thames Rd', 'NUll','Gujarat','India','145 895'); 22 | 23 | -- insert into star ratings table 24 | INSERT INTO `star_ratings`(`star_rating`, `star_rating_image`) 25 | VALUES 26 | (1,"/images/one_star.jpg"), 27 | (2,"/images/two_star.jpg"), 28 | (3,"/images/three_star.jpg"), 29 | (4,"/images/four_star.jpg"), 30 | (5,"/images/five_star.jpg"); 31 | 32 | INSERT INTO `department`(`department_id`, `department_name`, `department_description`) 33 | VALUES 34 | (1,'Kitchen','cooking'), 35 | (2,'Cleaning','sweep and mop'), 36 | (3,'Front Staff','handle bookings and query resolution'), 37 | (4,'Management','handles customer and resolve complaints'), 38 | (5,'Commute','pick up and drop'); 39 | 40 | INSERT INTO `room_type`(`room_type_id`, `room_type_name`, `room_cost`, `room_type_description`, `smoke_friendly`, `pet_friendly`) 41 | VALUES 42 | (1, 'Standard Room','103',"1 King Bed 323-sq-foot (30-sq-meter) room with city views",0,1), 43 | (2, 'Standard Twin Room','123',"Two Twin Bed 323-sq-foot (30-sq-meter) room with city views",1,1), 44 | (3, 'Executive Room','130',"1 King Bed 323-sq-foot (30-sq-meter) room with city views",0,0), 45 | (4, 'Club Room','159',"2 King Bed 323-sq-foot (30-sq-meter) room with city views",1,1); 46 | 47 | INSERT INTO `guests`(`guest_id`, `guest_first_name`, `guest_last_name`, `guest_contact_number`, `guest_email_address`, `guest_credit_card`, `guest_id_proof`, `addresses_address_id`) 48 | VALUES 49 | (1,'Jane','Doe','132-456-8564','jane.doe@gmail.com',NULL,'/images/drivingLicense1023',1), 50 | (2,'Jerry','Thachter','564-896-4752','jerry.ytsvg@gmail.com',NULL,'/images/passport45612',2), 51 | (3,'Rihanna','Perry','745-986-7451','rih.vfdj89@gmail.com',NULL,'/images/drivingLicense4889',3), 52 | (4,'Mathew','Jose','489-624-8633','mathew.jose@gmail.com',NULL,'/images/drivingLicense8945',4), 53 | (5,'Jessica','Smith','487-956-8963','jess.smith@gmail.com',NULL,'/images/passport7896',5); 54 | 55 | INSERT INTO `room_rate_discount`(`discount_id`, `discount_rate`, `start_month`, `end_month`, `room_type_room_type_id`) 56 | VALUES 57 | (1,50,1,3,1), 58 | (2,15,6,8,1), 59 | (3,15,9,12,1), 60 | (4,0,4,6,1), 61 | (1,50,1,3,2), 62 | (2,80,6,8,2), 63 | (3,15,9,12,2), 64 | (4,0,4,6,2), 65 | (1,50,1,3,3), 66 | (2,80,6,8,3), 67 | (3,15,9,12,3), 68 | (4,0,4,6,3); 69 | 70 | INSERT INTO `hotel_chain`(`hotel_chain_id`, `hotel_chain_name`, `hotel_chain_contact_number`, `hotel_chain_email_address`, `hotel_chain_website`, `hotel_chain_head_office_address_id`) 71 | VALUES 72 | (1,'Best Western Hotels','456-865-8956','bw123@gmail.com','https://www.bestwestern.com/',6), 73 | (2,'China Town Hotels','110-526-5647','chinatown123@gmail.com','https://www.chinatown.com/',16), 74 | (3,'Elite Hotels','546-874-6547','elite.tea213@gmail.com','https://www.elitendhe.com/',17), 75 | (4,'Cosmopolitan Hotels','852-741-9765','cosmo.hotels123@gmail.com','https://www.cosmopolitan.com/',18), 76 | (5,'Prestige Hotels','657-784-3647','prestige2453@gmail.com','https://www.prestige.com/',19); 77 | 78 | INSERT INTO `hotel`(`hotel_id`, `hotel_name`, `hotel_contact_number`, `hotel_email_address`, `hotel_website`, `hotel_description`, `hotel_floor_count`, `hotel_room_capacity`, `hotel_chain_id`, `addresses_address_id`, `star_ratings_star_rating`, `check_in_time`, `check_out_time`) 79 | VALUES 80 | (1,'King George Inn & Suites','604-502-9564','kgi123@gmail.com','https://www.kgi123.com/','A 2-mile drive from Besh Ba Gowah Archaeological Park.',5,45,1,7,4,'12:00:00','23:00:00'), 81 | (2,'Copper Hills Inn','547-964-9564','chinni123@gmail.com','https://www.chin23.com/','A 2-mile drive from Besh Ba Gowah Archaeological Park.',6,55,1,8,5,'12:00:00','23:00:00'), 82 | (3,'Sawmill Inn','547-964-3452','sawmill.inn@gmail.com','https://www.chin23.com/','A 3-mile drive from Fairview Park.',4,50,1,9,5,'12:00:00','23:00:00'), 83 | (4,'Northgate Inn','547-876-5422','northgate.inn@gmail.com','https://www.chin23.com/','A 4-mile drive from Conestoga Mall',3,40,1,10,5,'12:00:00','23:00:00'); 84 | 85 | 86 | INSERT INTO `rooms`(`room_id`, `room_number`, `rooms_type_rooms_type_id`, `hotel_hotel_id`) 87 | VALUES 88 | (1,1101,1,1), 89 | (2,1102,1,1), 90 | (3,1103,1,1), 91 | (4,1104,1,1), 92 | (5,1105,1,1), 93 | (6,1106,1,1), 94 | (7,1107,1,1), 95 | (8,1108,1,1), 96 | (9,1109,1,1), 97 | (10,1110,1,1), 98 | (11,1111,1,1), 99 | (12,1112,1,1), 100 | (13,1113,1,1), 101 | (14,1114,1,1), 102 | (15,1115,1,1), 103 | (16,1116,1,1), 104 | (17,1117,2,1), 105 | (18,1118,2,1), 106 | (19,1119,2,1), 107 | (20,1120,2,1), 108 | (21,1121,2,1), 109 | (22,1122,2,1), 110 | (23,1123,2,1), 111 | (24,1124,2,1), 112 | (25,1125,2,1), 113 | (26,1126,2,1), 114 | (27,1127,2,1), 115 | (28,1128,2,1), 116 | (29,1129,2,1), 117 | (30,1130,2,1), 118 | (31,1131,2,1), 119 | (32,1132,2,1), 120 | (33,1133,2,1), 121 | (34,1134,2,1), 122 | (35,1135,2,1); 123 | 124 | INSERT INTO `hotel_services`(`service_id`, `service_name`, `service_description`, `service_cost`, `hotel_hotel_id`) 125 | VALUES 126 | (1,'24-hour Room Service','There will be 24-hour Room Service to take care of customers needs',20,1), 127 | (2,'Currency Exchange','Foreign Currency Exchange facility available',80,1), 128 | (3,'Laundry','Laundry/Dry Cleaning available same day',10,1), 129 | (4,'Entertainment Room','Book and watch movies',50,2), 130 | (5,'Swimming Pool','Pool access to all the guests',100,2), 131 | (6,'Gym','24 Hour Gym',140,2); 132 | 133 | INSERT INTO `employees`(`emp_id`, `emp_first_name`, `emp_last_name`, `emp_designation`, `emp_contact_number`, `emp_email_address`, `department_department_id`, `addresses_address_id`, `hotel_hotel_id`) 134 | VALUES 135 | (1,'Jen','Fen','Waiter','123-789-7896','jen.rds@gmail.com',1,11,1), 136 | (2,'Tom','Pitt','Manager','565-789-7896','tom.pit@gmail.com',3,12,1), 137 | (3,'David','Lawrence','Cashier','852-789-7896','david.lawr@gmail.com',2,13,1), 138 | (4,'Joseph','Aniston','Cook','765-789-7896','joseph.anis@gmail.com',2,14,1), 139 | (5,'Jeny','Patel','Manager','531-789-7896','jeny.patel@gmail.com',3,15,1); 140 | 141 | INSERT INTO `hotel_chain_has_hotel`(`hotel_chains_hotel_chain_id`, `hotels_hotel_id`) 142 | VALUES 143 | (1,1), 144 | (1,2), 145 | (1,3), 146 | (1,4), 147 | (2,3), 148 | (2,4); 149 | 150 | INSERT INTO `bookings` (`booking_id`, `booking_date`, `duration_of_stay`, `check_in_date`, `check_out_date`, `booking_payment_type`, `total_rooms_booked`, `hotel_hotel_id`, `guests_guest_id`, `employees_emp_id`, `total_amount`) 151 | VALUES 152 | ('1', '2018-08-08 00:00:00', '5', '2018-08-10 12:00:00', '2018-08-15 23:00:00', 'cash', '1', '1', '1', '3', '590'), 153 | ('2', '2018-06-08 00:00:00', '20', '2018-06-08 12:00:00', '2018-06-28 23:00:00', 'card', '1', '1', '2', '1', '2300'), 154 | ('3', '2018-06-08 00:00:00', '10', '2018-06-08 12:00:00', '2018-06-18 23:00:00', 'card', '1', '1', '1', '3', '1100'), 155 | ('4', '2018-06-08 00:00:00', '2', '2018-06-08 12:00:00', '2018-06-10 23:00:00', 'card', '1', '1', '4', '1', '290'), 156 | ('5', '2018-06-08 00:00:00', '3', '2018-06-08 12:00:00', '2018-06-11 23:00:00', 'card', '1', '1', '2', '3', '350'), 157 | ('6', '2018-06-08 00:00:00', '5', '2018-06-08 12:00:00', '2018-06-13 23:00:00', 'card', '1', '1', '3', '3', '570'), 158 | ('7', '2018-08-13 00:00:00', '2', '2018-06-13 12:00:00', '2018-06-15 23:00:00', 'cash', '2', '1', '5', '4', '280'), 159 | ('8', '2018-08-10 00:00:00', '3', '2018-08-11 12:00:00', '2018-08-13 23:00:00', 'card', '1', '1', '3', '3', '350'), 160 | ('9', '2018-08-10 00:00:00', '5', '2018-08-12 12:00:00', '2018-08-16 23:00:00', 'card', '1', '1', '4', '3', '570'), 161 | ('10', '2018-08-14 00:00:00', '2', '2018-08-15 12:00:00', '2018-08-17 23:00:00', 'cash', '2', '1', '5', '4', '280'), 162 | ('11', '2018-08-14 00:00:00', '5', '2018-08-16 12:00:00', '2018-08-21 23:00:00', 'cash', '1', '1', '1', '3', '590'), 163 | ('12', '2018-08-14 00:00:00', '20', '2018-08-17 12:00:00', '2018-09-07 23:00:00', 'card', '1', '1', '2', '1', '2300'), 164 | ('13', '2018-08-14 00:00:00', '10', '2018-08-15 12:00:00', '2018-08-25 23:00:00', 'card', '1', '1', '1', '3', '1100'), 165 | ('14', '2018-08-14 00:00:00', '2', '2018-08-16 12:00:00', '2018-08-18 23:00:00', 'card', '2', '1', '4', '1', '290'), 166 | ('15', '2018-08-14 00:00:00', '3', '2018-08-17 12:00:00', '2018-08-20 23:00:00', 'card', '3', '1', '2', '3', '350'); 167 | 168 | 169 | INSERT INTO `rooms_booked` (`rooms_booked_id`, `bookings_booking_id`, `rooms_room_id`) 170 | VALUES 171 | ('1', '1', '1'), 172 | ('2', '2', '2'), 173 | ('3', '2', '3'), 174 | ('4', '2', '4'), 175 | ('5', '2', '5'), 176 | ('6', '2', '6'), 177 | ('7', '7', '7'), 178 | ('8', '7', '8'), 179 | ('9', '6', '9'), 180 | ('10','8','10'), 181 | ('11','9','11'), 182 | ('12','10','12'), 183 | ('13','10','13'), 184 | ('14', '11', '14'), 185 | ('15', '12', '15'), 186 | ('16', '13', '16'), 187 | ('17', '14', '17'), 188 | ('18', '14', '18'), 189 | ('19', '15', '19'), 190 | ('20', '15', '20'), 191 | ('21', '15', '21'); 192 | 193 | 194 | INSERT INTO `hotel_services_used_by_guests` (`service_used_id`, `hotel_services_service_id`, `bookings_booking_id`) 195 | VALUES ('1', '1', '2'), 196 | ('2', '2', '2'), 197 | ('3', '3', '2'); -------------------------------------------------------------------------------- /SQL Queries & Triggers & Views/create_hotel_database.sql: -------------------------------------------------------------------------------- 1 | -- MySQL Script generated by MySQL Workbench 2 | -- Fri Aug 10 18:48:44 2018 3 | -- Model: New Model Version: 1.0 4 | -- MySQL Workbench Forward Engineering 5 | 6 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 7 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 8 | SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; 9 | 10 | -- ----------------------------------------------------- 11 | -- Schema hotel_database 12 | -- ----------------------------------------------------- 13 | 14 | -- ----------------------------------------------------- 15 | -- Schema hotel_database 16 | -- ----------------------------------------------------- 17 | CREATE SCHEMA IF NOT EXISTS `hotel_database` DEFAULT CHARACTER SET utf8 ; 18 | USE `hotel_database` ; 19 | 20 | -- ----------------------------------------------------- 21 | -- Table `hotel_database`.`addresses` 22 | -- ----------------------------------------------------- 23 | DROP TABLE IF EXISTS `hotel_database`.`addresses` ; 24 | 25 | CREATE TABLE IF NOT EXISTS `hotel_database`.`addresses` ( 26 | `address_id` INT NOT NULL, 27 | `address_line1` VARCHAR(100) NULL, 28 | `address_line2` VARCHAR(100) NULL, 29 | `city` VARCHAR(45) NULL, 30 | `state` VARCHAR(45) NULL, 31 | `country` VARCHAR(45) NULL, 32 | `zipcode` VARCHAR(8) NULL, 33 | PRIMARY KEY (`address_id`)) 34 | ENGINE = InnoDB; 35 | 36 | 37 | -- ----------------------------------------------------- 38 | -- Table `hotel_database`.`hotel_chain` 39 | -- ----------------------------------------------------- 40 | DROP TABLE IF EXISTS `hotel_database`.`hotel_chain` ; 41 | 42 | CREATE TABLE IF NOT EXISTS `hotel_database`.`hotel_chain` ( 43 | `hotel_chain_id` INT NOT NULL, 44 | `hotel_chain_name` VARCHAR(45) NULL, 45 | `hotel_chain_contact_number` VARCHAR(12) NULL, 46 | `hotel_chain_email_address` VARCHAR(45) NULL, 47 | `hotel_chain_website` VARCHAR(45) NULL, 48 | `hotel_chain_head_office_address_id` INT NOT NULL, 49 | PRIMARY KEY (`hotel_chain_id`, `hotel_chain_head_office_address_id`), 50 | CONSTRAINT `fk_hotel_chains_addresses1` 51 | FOREIGN KEY (`hotel_chain_head_office_address_id`) 52 | REFERENCES `hotel_database`.`addresses` (`address_id`) 53 | ON DELETE NO ACTION 54 | ON UPDATE NO ACTION) 55 | ENGINE = InnoDB; 56 | 57 | CREATE INDEX `fk_hotel_chains_addresses1_idx` ON `hotel_database`.`hotel_chain` (`hotel_chain_head_office_address_id` ASC); 58 | 59 | 60 | -- ----------------------------------------------------- 61 | -- Table `hotel_database`.`star_ratings` 62 | -- ----------------------------------------------------- 63 | DROP TABLE IF EXISTS `hotel_database`.`star_ratings` ; 64 | 65 | CREATE TABLE IF NOT EXISTS `hotel_database`.`star_ratings` ( 66 | `star_rating` INT NOT NULL, 67 | `star_rating_image` VARCHAR(100) NULL, 68 | PRIMARY KEY (`star_rating`)) 69 | ENGINE = InnoDB; 70 | 71 | 72 | -- ----------------------------------------------------- 73 | -- Table `hotel_database`.`hotel` 74 | -- ----------------------------------------------------- 75 | DROP TABLE IF EXISTS `hotel_database`.`hotel` ; 76 | 77 | CREATE TABLE IF NOT EXISTS `hotel_database`.`hotel` ( 78 | `hotel_id` INT NOT NULL, 79 | `hotel_name` VARCHAR(45) NULL, 80 | `hotel_contact_number` VARCHAR(12) NULL, 81 | `hotel_email_address` VARCHAR(45) NULL, 82 | `hotel_website` VARCHAR(45) NULL, 83 | `hotel_description` VARCHAR(100) NULL, 84 | `hotel_floor_count` INT NULL, 85 | `hotel_room_capacity` INT NULL, 86 | `hotel_chain_id` INT NULL, 87 | `addresses_address_id` INT NOT NULL, 88 | `star_ratings_star_rating` INT NOT NULL, 89 | `check_in_time` TIME NULL, 90 | `check_out_time` TIME NULL, 91 | PRIMARY KEY (`hotel_id`, `addresses_address_id`, `star_ratings_star_rating`), 92 | CONSTRAINT `fk_hotels_addresses1` 93 | FOREIGN KEY (`addresses_address_id`) 94 | REFERENCES `hotel_database`.`addresses` (`address_id`) 95 | ON DELETE NO ACTION 96 | ON UPDATE NO ACTION, 97 | CONSTRAINT `fk_hotel_star_ratings1` 98 | FOREIGN KEY (`star_ratings_star_rating`) 99 | REFERENCES `hotel_database`.`star_ratings` (`star_rating`) 100 | ON DELETE NO ACTION 101 | ON UPDATE NO ACTION) 102 | ENGINE = InnoDB 103 | COMMENT = ' '; 104 | 105 | CREATE INDEX `fk_hotels_addresses1_idx` ON `hotel_database`.`hotel` (`addresses_address_id` ASC); 106 | 107 | CREATE INDEX `fk_hotel_star_ratings1_idx` ON `hotel_database`.`hotel` (`star_ratings_star_rating` ASC); 108 | 109 | 110 | -- ----------------------------------------------------- 111 | -- Table `hotel_database`.`room_type` 112 | -- ----------------------------------------------------- 113 | DROP TABLE IF EXISTS `hotel_database`.`room_type` ; 114 | 115 | CREATE TABLE IF NOT EXISTS `hotel_database`.`room_type` ( 116 | `room_type_id` INT NOT NULL, 117 | `room_type_name` VARCHAR(45) NULL, 118 | `room_cost` DECIMAL(10,2) NULL, 119 | `room_type_description` VARCHAR(100) NULL, 120 | `smoke_friendly` TINYINT(1) NULL, 121 | `pet_friendly` TINYINT(1) NULL, 122 | PRIMARY KEY (`room_type_id`)) 123 | ENGINE = InnoDB; 124 | 125 | 126 | -- ----------------------------------------------------- 127 | -- Table `hotel_database`.`rooms` 128 | -- ----------------------------------------------------- 129 | DROP TABLE IF EXISTS `hotel_database`.`rooms` ; 130 | 131 | CREATE TABLE IF NOT EXISTS `hotel_database`.`rooms` ( 132 | `room_id` INT NOT NULL, 133 | `room_number` INT(4) NULL, 134 | `rooms_type_rooms_type_id` INT NOT NULL, 135 | `hotel_hotel_id` INT NOT NULL, 136 | PRIMARY KEY (`room_id`, `rooms_type_rooms_type_id`, `hotel_hotel_id`), 137 | CONSTRAINT `fk_rooms_rooms_type1` 138 | FOREIGN KEY (`rooms_type_rooms_type_id`) 139 | REFERENCES `hotel_database`.`room_type` (`room_type_id`) 140 | ON DELETE NO ACTION 141 | ON UPDATE NO ACTION, 142 | CONSTRAINT `fk_rooms_hotel1` 143 | FOREIGN KEY (`hotel_hotel_id`) 144 | REFERENCES `hotel_database`.`hotel` (`hotel_id`) 145 | ON DELETE NO ACTION 146 | ON UPDATE NO ACTION) 147 | ENGINE = InnoDB; 148 | 149 | CREATE INDEX `fk_rooms_rooms_type1_idx` ON `hotel_database`.`rooms` (`rooms_type_rooms_type_id` ASC); 150 | 151 | CREATE INDEX `fk_rooms_hotel1_idx` ON `hotel_database`.`rooms` (`hotel_hotel_id` ASC); 152 | 153 | 154 | -- ----------------------------------------------------- 155 | -- Table `hotel_database`.`guests` 156 | -- ----------------------------------------------------- 157 | DROP TABLE IF EXISTS `hotel_database`.`guests` ; 158 | 159 | CREATE TABLE IF NOT EXISTS `hotel_database`.`guests` ( 160 | `guest_id` INT NOT NULL, 161 | `guest_first_name` VARCHAR(45) NULL, 162 | `guest_last_name` VARCHAR(45) NULL, 163 | `guest_contact_number` VARCHAR(12) NULL, 164 | `guest_email_address` VARCHAR(45) NULL, 165 | `guest_credit_card` VARCHAR(45) NULL, 166 | `guest_id_proof` VARCHAR(45) NULL, 167 | `addresses_address_id` INT NOT NULL, 168 | PRIMARY KEY (`guest_id`, `addresses_address_id`), 169 | CONSTRAINT `fk_guests_addresses1` 170 | FOREIGN KEY (`addresses_address_id`) 171 | REFERENCES `hotel_database`.`addresses` (`address_id`) 172 | ON DELETE NO ACTION 173 | ON UPDATE NO ACTION) 174 | ENGINE = InnoDB 175 | COMMENT = ' '; 176 | 177 | CREATE INDEX `fk_guests_addresses1_idx` ON `hotel_database`.`guests` (`addresses_address_id` ASC); 178 | 179 | 180 | -- ----------------------------------------------------- 181 | -- Table `hotel_database`.`department` 182 | -- ----------------------------------------------------- 183 | DROP TABLE IF EXISTS `hotel_database`.`department` ; 184 | 185 | CREATE TABLE IF NOT EXISTS `hotel_database`.`department` ( 186 | `department_id` INT NOT NULL, 187 | `department_name` VARCHAR(45) NULL, 188 | `department_description` VARCHAR(100) NULL, 189 | PRIMARY KEY (`department_id`)) 190 | ENGINE = InnoDB; 191 | 192 | 193 | -- ----------------------------------------------------- 194 | -- Table `hotel_database`.`employees` 195 | -- ----------------------------------------------------- 196 | DROP TABLE IF EXISTS `hotel_database`.`employees` ; 197 | 198 | CREATE TABLE IF NOT EXISTS `hotel_database`.`employees` ( 199 | `emp_id` INT NOT NULL, 200 | `emp_first_name` VARCHAR(45) NULL, 201 | `emp_last_name` VARCHAR(45) NULL, 202 | `emp_designation` VARCHAR(45) NULL, 203 | `emp_contact_number` VARCHAR(12) NULL, 204 | `emp_email_address` VARCHAR(45) NULL, 205 | `department_department_id` INT NOT NULL, 206 | `addresses_address_id` INT NOT NULL, 207 | `hotel_hotel_id` INT NOT NULL, 208 | PRIMARY KEY (`emp_id`, `department_department_id`, `addresses_address_id`, `hotel_hotel_id`), 209 | CONSTRAINT `fk_employees_services1` 210 | FOREIGN KEY (`department_department_id`) 211 | REFERENCES `hotel_database`.`department` (`department_id`) 212 | ON DELETE NO ACTION 213 | ON UPDATE NO ACTION, 214 | CONSTRAINT `fk_employees_addresses1` 215 | FOREIGN KEY (`addresses_address_id`) 216 | REFERENCES `hotel_database`.`addresses` (`address_id`) 217 | ON DELETE NO ACTION 218 | ON UPDATE NO ACTION, 219 | CONSTRAINT `fk_employees_hotel1` 220 | FOREIGN KEY (`hotel_hotel_id`) 221 | REFERENCES `hotel_database`.`hotel` (`hotel_id`) 222 | ON DELETE NO ACTION 223 | ON UPDATE NO ACTION) 224 | ENGINE = InnoDB; 225 | 226 | CREATE INDEX `fk_employees_services1_idx` ON `hotel_database`.`employees` (`department_department_id` ASC); 227 | 228 | CREATE INDEX `fk_employees_addresses1_idx` ON `hotel_database`.`employees` (`addresses_address_id` ASC); 229 | 230 | CREATE INDEX `fk_employees_hotel1_idx` ON `hotel_database`.`employees` (`hotel_hotel_id` ASC); 231 | 232 | 233 | -- ----------------------------------------------------- 234 | -- Table `hotel_database`.`bookings` 235 | -- ----------------------------------------------------- 236 | DROP TABLE IF EXISTS `hotel_database`.`bookings` ; 237 | 238 | CREATE TABLE IF NOT EXISTS `hotel_database`.`bookings` ( 239 | `booking_id` INT NOT NULL, 240 | `booking_date` DATETIME NULL, 241 | `duration_of_stay` VARCHAR(10) NULL, 242 | `check_in_date` DATETIME NULL, 243 | `check_out_date` DATETIME NULL, 244 | `booking_payment_type` VARCHAR(45) NULL, 245 | `total_rooms_booked` INT NULL, 246 | `hotel_hotel_id` INT NOT NULL, 247 | `guests_guest_id` INT NOT NULL, 248 | `employees_emp_id` INT NOT NULL, 249 | `total_amount` DECIMAL(10,2) NULL, 250 | PRIMARY KEY (`booking_id`, `hotel_hotel_id`, `guests_guest_id`, `employees_emp_id`), 251 | CONSTRAINT `fk_bookings_hotel1` 252 | FOREIGN KEY (`hotel_hotel_id`) 253 | REFERENCES `hotel_database`.`hotel` (`hotel_id`) 254 | ON DELETE NO ACTION 255 | ON UPDATE NO ACTION, 256 | CONSTRAINT `fk_bookings_guests1` 257 | FOREIGN KEY (`guests_guest_id`) 258 | REFERENCES `hotel_database`.`guests` (`guest_id`) 259 | ON DELETE NO ACTION 260 | ON UPDATE NO ACTION, 261 | CONSTRAINT `fk_bookings_employees1` 262 | FOREIGN KEY (`employees_emp_id` ) 263 | REFERENCES `hotel_database`.`employees` (`emp_id` ) 264 | ON DELETE NO ACTION 265 | ON UPDATE NO ACTION) 266 | ENGINE = InnoDB; 267 | 268 | CREATE INDEX `fk_bookings_hotel1_idx` ON `hotel_database`.`bookings` (`hotel_hotel_id` ASC); 269 | 270 | CREATE INDEX `fk_bookings_guests1_idx` ON `hotel_database`.`bookings` (`guests_guest_id` ASC); 271 | 272 | CREATE INDEX `fk_bookings_employees1_idx` ON `hotel_database`.`bookings` (`employees_emp_id` ASC); 273 | 274 | 275 | -- ----------------------------------------------------- 276 | -- Table `hotel_database`.`hotel_chain_has_hotel` 277 | -- ----------------------------------------------------- 278 | DROP TABLE IF EXISTS `hotel_database`.`hotel_chain_has_hotel` ; 279 | 280 | CREATE TABLE IF NOT EXISTS `hotel_database`.`hotel_chain_has_hotel` ( 281 | `hotel_chains_hotel_chain_id` INT NOT NULL, 282 | 283 | `hotels_hotel_id` INT NOT NULL, 284 | PRIMARY KEY (`hotel_chains_hotel_chain_id`, `hotels_hotel_id`), 285 | CONSTRAINT `fk_hotel_chains_has_hotels_hotel_chains1` 286 | FOREIGN KEY (`hotel_chains_hotel_chain_id`) 287 | REFERENCES `hotel_database`.`hotel_chain` (`hotel_chain_id` ) 288 | ON DELETE NO ACTION 289 | ON UPDATE NO ACTION, 290 | CONSTRAINT `fk_hotel_chains_has_hotels_hotels1` 291 | FOREIGN KEY (`hotels_hotel_id`) 292 | REFERENCES `hotel_database`.`hotel` (`hotel_id`) 293 | ON DELETE NO ACTION 294 | ON UPDATE NO ACTION) 295 | ENGINE = InnoDB; 296 | 297 | CREATE INDEX `fk_hotel_chains_has_hotels_hotels1_idx` ON `hotel_database`.`hotel_chain_has_hotel` (`hotels_hotel_id` ASC); 298 | 299 | CREATE INDEX `fk_hotel_chains_has_hotels_hotel_chains1_idx` ON `hotel_database`.`hotel_chain_has_hotel` (`hotel_chains_hotel_chain_id` ASC); 300 | 301 | 302 | -- ----------------------------------------------------- 303 | -- Table `hotel_database`.`room_rate_discount` 304 | -- ----------------------------------------------------- 305 | DROP TABLE IF EXISTS `hotel_database`.`room_rate_discount` ; 306 | 307 | CREATE TABLE IF NOT EXISTS `hotel_database`.`room_rate_discount` ( 308 | `discount_id` INT NOT NULL, 309 | `discount_rate` DECIMAL(10,2) NULL, 310 | `start_month` TINYINT(1) NULL, 311 | `end_month` TINYINT(1) NULL, 312 | `room_type_room_type_id` INT NOT NULL, 313 | PRIMARY KEY (`discount_id`, `room_type_room_type_id`), 314 | CONSTRAINT `fk_room_rate_discount_room_type1` 315 | FOREIGN KEY (`room_type_room_type_id`) 316 | REFERENCES `hotel_database`.`room_type` (`room_type_id`) 317 | ON DELETE NO ACTION 318 | ON UPDATE NO ACTION) 319 | ENGINE = InnoDB; 320 | 321 | CREATE INDEX `fk_room_rate_discount_room_type1_idx` ON `hotel_database`.`room_rate_discount` (`room_type_room_type_id` ASC); 322 | 323 | 324 | -- ----------------------------------------------------- 325 | -- Table `hotel_database`.`rooms_booked` 326 | -- ----------------------------------------------------- 327 | DROP TABLE IF EXISTS `hotel_database`.`rooms_booked` ; 328 | 329 | CREATE TABLE IF NOT EXISTS `hotel_database`.`rooms_booked` ( 330 | `rooms_booked_id` INT NOT NULL, 331 | `bookings_booking_id` INT NOT NULL, 332 | `rooms_room_id` INT NOT NULL, 333 | PRIMARY KEY (`rooms_booked_id`, `bookings_booking_id`, `rooms_room_id`), 334 | CONSTRAINT `fk_rooms_booked_bookings1` 335 | FOREIGN KEY (`bookings_booking_id`) 336 | REFERENCES `hotel_database`.`bookings` (`booking_id`) 337 | ON DELETE NO ACTION 338 | ON UPDATE NO ACTION, 339 | CONSTRAINT `fk_rooms_booked_rooms1` 340 | FOREIGN KEY (`rooms_room_id`) 341 | REFERENCES `hotel_database`.`rooms` (`room_id`) 342 | ON DELETE NO ACTION 343 | ON UPDATE NO ACTION) 344 | ENGINE = InnoDB; 345 | 346 | CREATE INDEX `fk_rooms_booked_bookings1_idx` ON `hotel_database`.`rooms_booked` (`bookings_booking_id` ASC); 347 | 348 | CREATE INDEX `fk_rooms_booked_rooms1_idx` ON `hotel_database`.`rooms_booked` (`rooms_room_id` ASC); 349 | 350 | 351 | -- ----------------------------------------------------- 352 | -- Table `hotel_database`.`hotel_services` 353 | -- ----------------------------------------------------- 354 | DROP TABLE IF EXISTS `hotel_database`.`hotel_services` ; 355 | 356 | CREATE TABLE IF NOT EXISTS `hotel_database`.`hotel_services` ( 357 | `service_id` INT NOT NULL, 358 | `service_name` VARCHAR(45) NULL, 359 | `service_description` VARCHAR(100) NULL, 360 | `service_cost` DECIMAL(10,2) NULL, 361 | `hotel_hotel_id` INT NOT NULL, 362 | PRIMARY KEY (`service_id`, `hotel_hotel_id`), 363 | CONSTRAINT `fk_hotel_services_hotel1` 364 | FOREIGN KEY (`hotel_hotel_id`) 365 | REFERENCES `hotel_database`.`hotel` (`hotel_id`) 366 | ON DELETE NO ACTION 367 | ON UPDATE NO ACTION) 368 | ENGINE = InnoDB; 369 | 370 | CREATE INDEX `fk_hotel_services_hotel1_idx` ON `hotel_database`.`hotel_services` (`hotel_hotel_id` ASC); 371 | 372 | 373 | -- ----------------------------------------------------- 374 | -- Table `hotel_database`.`hotel_services_used_by_guests` 375 | -- ----------------------------------------------------- 376 | DROP TABLE IF EXISTS `hotel_database`.`hotel_services_used_by_guests` ; 377 | 378 | CREATE TABLE IF NOT EXISTS `hotel_database`.`hotel_services_used_by_guests` ( 379 | `service_used_id` INT NOT NULL, 380 | `hotel_services_service_id` INT NOT NULL, 381 | `bookings_booking_id` INT NOT NULL, 382 | PRIMARY KEY (`service_used_id`, `hotel_services_service_id`, `bookings_booking_id`), 383 | CONSTRAINT `fk_hotel_services_has_bookings_hotel_services1` 384 | FOREIGN KEY (`hotel_services_service_id`) 385 | REFERENCES `hotel_database`.`hotel_services` (`service_id`) 386 | ON DELETE NO ACTION 387 | ON UPDATE NO ACTION, 388 | CONSTRAINT `fk_hotel_services_has_bookings_bookings1` 389 | FOREIGN KEY (`bookings_booking_id`) 390 | REFERENCES `hotel_database`.`bookings` (`booking_id`) 391 | ON DELETE NO ACTION 392 | ON UPDATE NO ACTION) 393 | ENGINE = InnoDB; 394 | 395 | CREATE INDEX `fk_hotel_services_has_bookings_bookings1_idx` ON `hotel_database`.`hotel_services_used_by_guests` (`bookings_booking_id` ASC); 396 | 397 | CREATE INDEX `fk_hotel_services_has_bookings_hotel_services1_idx` ON `hotel_database`.`hotel_services_used_by_guests` (`hotel_services_service_id` ASC); 398 | 399 | 400 | SET SQL_MODE=@OLD_SQL_MODE; 401 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 402 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 403 | --------------------------------------------------------------------------------