0% found this document useful (0 votes)
8 views

Restaurant Database

Uploaded by

Emma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Restaurant Database

Uploaded by

Emma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Restaurant Database

Creation process
For an ER Diagram I created four entities, Customer, Booking, Table and Restaurant. I
set a one to many relationship between Customer and Booking, since customer is able to make
many booking but one booking cannot be assigned to more than one customer. The entity of
customer represents people making the booking. The attributes I assigned to the entity are
CustomerID which is the primary key, FirstName, LastName and a Phone. The Booking entity
represents the reservation made by a customer and has BookingID, as the primary key,
DateTimeOfBooking, the date and time for a booking so customers know which tables are still
availiable, NumOfGuests, number of guests, and to connect it with the Customer entity I added
CustomerID as a foreign key.
Then I have a Booking and Table relationship, which I set to many to many relation,
and created the junction table called ‘BookingOf ‘between these two, in order to be able to
obtain data later on.
The Table entity is connected to the Restaurant entity, which I think in my case is not
necessary to have, since I only have one restaurant, but having the restaurant entity would be a
good solution if the number of restaurants would expand in the future.
For the Table entity I added TableID, as a primary key, TableNumber, for more structure
and better orientation when viewing the table in front end, also Capacity, for the maximum
capacity for tables, and RestaurantID as a foreign key.
Lastly, the Restaurant entity has RestaurantID as primary key, Name, and a composed attribute
called Address with Street and City attributes.

To transfer the ER diagram I put all the attributes to the tables and at the same time made sure
that there a no multivalued or composed attributes, in order to normalize the database to 1NF.
The only change I had to do was instead of Address attribute, put its atomic attributes to the
table. To fulfill the 2NF and 3NF I didn’t have to do any other changes to the database.
SQL Queries
The queries to show the list of all tables in the restaurant.
SELECT TableID
FROM `Table`;

To get a list of all customers and when they arrive at the restaurant ordered by the date, I used
the following query.
SELECT Booking.BookingID, Booking.DateOfBooking FROM Booking
JOIN Customer ON Booking.CustomerID = Customer.CustomerID
WHERE Customer.CustomerID = 1
ORDER BY `Booking`.`DateOfBooking`;

To get a list for all the bookings for a given tableID, including the customers for a chosen date
I used this query.
SELECT Booking.BookingID, Booking.DateOfBooking,Booking.NumOfGuests,
Customer.FirstName, Customer.LastName FROM Booking
JOIN
BookingOf ON Booking.BookingID = BookingOf.BookingID
JOIN
Customer ON Booking.CustomerID = Customer.CustomerID
WHERE
BookingOf.TableID = 1
AND Booking.DateOfBooking = '2023-10-10';

You might also like