0% found this document useful (0 votes)
50 views10 pages

Database Code

The document outlines the creation of a database for a Hotel Management System, including tables for Managers, Branches, Room Types, Rooms, Customers, Bookings, Booking Rooms, Invoices, and Ratings. It provides SQL commands for creating these tables and inserting sample data into them. The structure supports managing hotel operations, customer reservations, and feedback effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views10 pages

Database Code

The document outlines the creation of a database for a Hotel Management System, including tables for Managers, Branches, Room Types, Rooms, Customers, Bookings, Booking Rooms, Invoices, and Ratings. It provides SQL commands for creating these tables and inserting sample data into them. The structure supports managing hotel operations, customer reservations, and feedback effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

--

==============================================
============================

-- This part covers all the databases required for a Hotel Management
System

--
==============================================
============================

-- Create the database used for the Hotel Management System.

CREATE DATABASE Soft_Hotel_Management_System;

-- Uses the created database.

USE Soft_Hotel_Management_System;

-- Manager Table: For storing the details for the Branch Managers

CREATE TABLE Manager (

ManagerID VARCHAR(10) PRIMARY KEY,

ManagerFName VARCHAR(50) NOT NULL,

ManagerLName VARCHAR(50) NOT NULL,

ContactNumber VARCHAR(20) NOT NULL

);

-- Branch Table: For storing the details of each hotel branch.

CREATE TABLE Branch (

BranchID VARCHAR(10) PRIMARY KEY,

BranchName VARCHAR(100) NOT NULL,

Address VARCHAR(255) NOT NULL,


Country VARCHAR(50) NOT NULL,

ManagerID VARCHAR(10) UNIQUE NOT NULL,

FOREIGN KEY (ManagerID) REFERENCES Manager(ManagerID)

);

-- RoomType Table: For Defining the different types of rooms available.

CREATE TABLE RoomType (

RoomTypeID VARCHAR(10) PRIMARY KEY,

TypeName VARCHAR(50) NOT NULL,

Capacity INT NOT NULL,

RoomRate DECIMAL(10, 2) NOT NULL

);

-- Room Table: For storing details for every individual room in each branch.

CREATE TABLE Room (

RoomID VARCHAR(10) PRIMARY KEY,

RoomNumber VARCHAR(10) NOT NULL,

BranchID VARCHAR(10) NOT NULL,

RoomTypeID VARCHAR(10) NOT NULL,

FOREIGN KEY (BranchID) REFERENCES Branch(BranchID),

FOREIGN KEY (RoomTypeID) REFERENCES RoomType(RoomTypeID)

);

-- Customer Table: For storing details of registered members.

CREATE TABLE Customer (

CustomerID VARCHAR(10) PRIMARY KEY,

FirstName VARCHAR(50) NOT NULL,


LastName VARCHAR(50) NOT NULL,

ContactNumber VARCHAR(20) NOT NULL,

Email VARCHAR(100) UNIQUE NOT NULL,

Address VARCHAR(255),

Gender VARCHAR(10) -- Added for query vii

);

-- Booking Table: For storing details of each reservation.

CREATE TABLE Booking (

BookingID VARCHAR(10) PRIMARY KEY,

BookingDate DATE NOT NULL,

CheckInDate DATE NOT NULL,

CheckOutDate DATE NOT NULL,

EmergencyContact VARCHAR(20) NOT NULL,

SpecialRequest TEXT,

CustomerID VARCHAR(10) NOT NULL,

BranchID VARCHAR(10) NOT NULL,

FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),

FOREIGN KEY (BranchID) REFERENCES Branch(BranchID)

);

-- BookingRoom Table: A junction table to link bookings with multiple rooms.

CREATE TABLE BookingRoom (

BookingID VARCHAR(10) NOT NULL,

RoomID VARCHAR(10) NOT NULL,

PRIMARY KEY (BookingID, RoomID),

FOREIGN KEY (BookingID) REFERENCES Booking(BookingID),


FOREIGN KEY (RoomID) REFERENCES Room(RoomID)

);

-- Invoice Table: For storing payment details for each booking.

CREATE TABLE Invoice (

InvoiceID VARCHAR(10) PRIMARY KEY,

InvoiceDate DATE NOT NULL,

TotalAmount DECIMAL(10, 2) NOT NULL,

BookingID VARCHAR(10) UNIQUE NOT NULL,

FOREIGN KEY (BookingID) REFERENCES Booking(BookingID)

);

-- Rating Table: For storing customer feedback after their stay.

CREATE TABLE Rating (

RatingID VARCHAR(10) PRIMARY KEY,

Score INT CHECK (Score BETWEEN 1 AND 5),

ReviewText TEXT,

RatingDate DATE,

BookingID VARCHAR(10) UNIQUE NOT NULL,

FOREIGN KEY (BookingID) REFERENCES Booking(BookingID)

);

--
==============================================
=======================
-- Data Manipulation Language (DML) - INSERT Statements

-- We add sample data to the Database.

--
==============================================
=======================

-- Managers

INSERT INTO Manager (ManagerID, ManagerFName, ManagerLName,


ContactNumber) VALUES

('M01', 'Alice', 'Tan', '+60123456789'),

('M02', 'Bikram', 'Shrestha', '+9779841234567'),

('M03', 'John', 'Smith', '+12125550123'),

('M04', 'Emily', 'Jones', '+61298765432');

-- Branches

INSERT INTO Branch (BranchID, BranchName, Address, Country, ManagerID)


VALUES

('B01', 'Kuala Lumpur', '125 Jalan Ampang, 50450 Kuala Lumpur', 'Malaysia',
'M01'),

('B02', 'Kathmandu', 'Thamel Marg, Kathmandu 44600', 'Nepal', 'M02'),

('B03', 'New York', '489 Park Avenue, New York, NY 10022', 'USA', 'M03'),

('B04', 'Sydney', '168 George Street, Sydney NSW 2000', 'Australia', 'M04');

-- Room Types

INSERT INTO RoomType (RoomTypeID, TypeName, Capacity, RoomRate)


VALUES

('RT01', 'Standard Double', 2, 250.00),

('RT02', 'Standard Twin', 2, 250.00),

('RT03', 'Deluxe Double', 2, 450.00);


-- Rooms (5 rooms per branch)

-- Kuala Lumpur Rooms

INSERT INTO Room (RoomID, RoomNumber, BranchID, RoomTypeID) VALUES

('R101', '101', 'B01', 'RT01'), ('R102', '102', 'B01', 'RT02'), ('R103', '103',
'B01', 'RT03'), ('R104', '104', 'B01', 'RT01'), ('R105', '105', 'B01', 'RT03');

-- Kathmandu Rooms

INSERT INTO Room (RoomID, RoomNumber, BranchID, RoomTypeID) VALUES

('R201', '101', 'B02', 'RT01'), ('R202', '102', 'B02', 'RT02'), ('R203', '103',
'B02', 'RT02'), ('R204', '104', 'B02', 'RT03'), ('R205', '105', 'B02', 'RT01');

-- New York Rooms

INSERT INTO Room (RoomID, RoomNumber, BranchID, RoomTypeID) VALUES

('R301', '101', 'B03', 'RT03'), ('R302', '102', 'B03', 'RT03'), ('R303', '103',
'B03', 'RT01'), ('R304', '104', 'B03', 'RT02'), ('R305', '105', 'B03', 'RT01');

-- Sydney Rooms

INSERT INTO Room (RoomID, RoomNumber, BranchID, RoomTypeID) VALUES

('R401', '101', 'B04', 'RT01'), ('R402', '102', 'B04', 'RT02'), ('R403', '103',
'B04', 'RT03'), ('R404', '104', 'B04', 'RT01'), ('R405', '105', 'B04', 'RT02');

-- Customers

INSERT INTO Customer (CustomerID, FirstName, LastName, ContactNumber,


Email, Address, Gender) VALUES

('C001', 'David', 'Lee', '111-222-3333', 'david.lee@example.com', '1 Main St,


Anytown', 'Male'),

('C002', 'Sarah', 'Chen', '444-555-6666', 'sarah.chen@example.com', '2 Oak


Ave, Somecity', 'Female'),
('C003', 'Michael', 'Brown', '777-888-9999', 'michael.b@example.com', '3 Pine
Ln, Yourtown', 'Male'),

('C004', 'Priya', 'Patel', '123-456-7890', 'priya.patel@example.com', '4 Maple


Dr, Heretown', 'Female'),

('C005', 'Ken', 'Watanabe', '555-123-4567', 'ken.w@example.com', '5 Elm Ct,


Histown', 'Male'),

('C006', 'Laura', 'Garcia', '888-765-4321', 'laura.g@example.com', '6 Birch


Rd, Ourtown', 'Female'),

('C007', 'Tom', 'Harris', '222-333-1111', 'tom.h@example.com', '7 Cedar PI,


Newtown', 'Male');

-- Bookings (Expanded to cover 2022-2025)

INSERT INTO Booking (BookingID, BookingDate, CheckInDate, CheckOutDate,


EmergencyContact, CustomerID, BranchID) VALUES

-- 2022 Bookings

('B001', '2022-11-20', '2022-12-15', '2022-12-18', '555-123-4567', 'C005',


'B02'),

('B002', '2022-12-10', '2022-12-28', '2022-12-30', '222-333-1111', 'C007',


'B01'),

-- 2023 Bookings

('B003', '2023-01-10', '2023-02-20', '2023-02-23', '111-222-3333', 'C001',


'B01'),

('B004', '2023-02-15', '2023-03-10', '2023-03-12', '444-555-6666', 'C002',


'B03'),

('B005', '2023-03-20', '2023-04-05', '2023-04-07', '123-456-7890', 'C004',


'B04'),

('B006', '2023-04-25', '2023-05-15', '2023-05-18', '111-222-3333', 'C001',


'B02'),

('B007', '2023-05-10', '2023-06-01', '2023-06-03', '444-555-6666', 'C002',


'B01'),
('B008', '2023-06-15', '2023-07-20', '2023-07-22', '777-888-9999', 'C003',
'B01'),

('B009', '2023-07-01', '2023-08-10', '2023-08-12', '111-222-3333', 'C001',


'B01'),

('B010', '2023-08-05', '2023-09-01', '2023-09-03', '111-222-3333', 'C001',


'B03'),

-- 2024 Bookings

('B011', '2024-01-05', '2024-01-20', '2024-01-23', '888-765-4321', 'C006',


'B04'),

('B012', '2024-02-18', '2024-03-05', '2024-03-08', '444-555-6666', 'C002',


'B03'),

('B013', '2024-03-10', '2024-04-01', '2024-04-04', '777-888-9999', 'C003',


'B01'),

('B014', '2024-05-22', '2024-06-10', '2024-06-13', '123-456-7890', 'C004',


'B02'),

('B015', '2024-07-30', '2024-08-15', '2024-08-18', '111-222-3333', 'C001',


'B04'),

('B016', '2024-09-12', '2024-10-01', '2024-10-04', '555-123-4567', 'C005',


'B03'),

('B017', '2024-10-02', '2024-11-05', '2024-11-08', '777-888-9999', 'C003',


'B03'),

-- 2025 Bookings (Future)

('B018', '2024-11-15', '2025-01-15', '2025-01-18', '888-765-4321', 'C006',


'B01'),

('B019', '2024-12-01', '2025-03-01', '2025-03-04', '111-222-3333', 'C001',


'B02'),

('B020', '2024-12-20', '2025-04-10', '2025-04-13', '444-555-6666', 'C002',


'B04');

-- BookingRoom links

INSERT INTO BookingRoom (BookingID, RoomID) VALUES


('B001', 'R201'), ('B002', 'R105'), ('B003', 'R101'), ('B004', 'R301'), ('B005',
'R401'),

('B006', 'R202'), ('B007', 'R102'), ('B008', 'R103'), ('B009', 'R104'), ('B010',


'R302'),

('B011', 'R402'), ('B012', 'R303'), ('B013', 'R101'), ('B014', 'R203'), ('B015',


'R403'),

('B016', 'R304'), ('B017', 'R305'), ('B018', 'R102'), ('B019', 'R204'), ('B020',


'R404');

-- Invoices

INSERT INTO Invoice (InvoiceID, InvoiceDate, TotalAmount, BookingID)


VALUES

('INV001', '2022-11-21', 750.00, 'B001'), ('INV002', '2022-12-11', 900.00,


'B002'),

('INV003', '2023-01-11', 750.00, 'B003'), ('INV004', '2023-02-16', 900.00,


'B004'),

('INV005', '2023-03-21', 500.00, 'B005'), ('INV006', '2023-04-26', 825.00,


'B006'),

('INV007', '2023-05-11', 550.00, 'B007'), ('INV008', '2023-06-16', 900.00,


'B008'),

('INV009', '2023-07-02', 500.00, 'B009'), ('INV010', '2023-08-06', 900.00,


'B010'),

('INV011', '2024-01-06', 825.00, 'B011'), ('INV012', '2024-02-19', 750.00,


'B012'),

('INV013', '2024-03-11', 750.00, 'B013'), ('INV014', '2024-05-23', 825.00,


'B014'),

('INV015', '2024-07-31', 1350.00, 'B015'), ('INV016', '2024-09-13', 825.00,


'B016'),

('INV017', '2024-10-03', 750.00, 'B017'), ('INV018', '2024-11-16', 825.00,


'B018'),

('INV019', '2024-12-02', 1350.00, 'B019'), ('INV020', '2024-12-21', 750.00,


'B020');
-- Ratings

INSERT INTO Rating (RatingID, Score, ReviewText, RatingDate, BookingID)


VALUES

('RA01', 5, 'Wonderful experience in Kathmandu!', '2022-12-20', 'B001'),

('RA02', 4, 'Great hotel, very clean.', '2023-01-02', 'B002'),

('RA03', 5, 'Excellent stay, great service!', '2023-02-24', 'B003'),

('RA04', 4, 'Very nice hotel, but a bit pricey.', '2023-03-13', 'B004'),

('RA05', 5, 'Loved the view from my room.', '2023-04-08', 'B005'),

('RA06', 4, 'Clean rooms and friendly staff.', '2023-06-04', 'B007'),

('RA07', 3, 'It was okay. The location is convenient.', '2023-07-23', 'B008'),

('RA08', 5, 'Fantastic service at the Sydney branch.', '2024-01-25', 'B011'),

('RA09', 4, 'Would recommend the New York hotel.', '2024-03-10', 'B012'),

('RA10', 5, 'Priya had a great time in Kathmandu.', '2024-06-15', 'B014');

SELECT * FROM Manager;

SELECT * FROM Branch;

SELECT * FROM RoomType;

SELECT * FROM Room;

SELECT * FROM Customer;

SELECT * FROM Booking;

SELECT * FROM BookingRoom;

SELECT * FROM Invoice;

SELECT * FROM Rating;

You might also like