TheoryMidterm CSC371
TheoryMidterm CSC371
Question 2: (8 Marks)
For the schema provided in Q.1, write an SQL script to create the tables. Implement, where possible, the keys and
other constraints and enforce the relationships as per ERD devised in Q1.D. All constraints must be added after
the tables are created using separate SQL queries.
A. Consider the relational schema discussed in Q.1. Describe the relations that would be produced by the
following relational algebra operations:
a. ΠhotelNo(σprice > 50(Room))
Projects hotelNo. From table ‘room’ which have rooms with price higher than 50
b. σHotel.hotelNo = Room.hotelNo(Hotel × Room)
cartesian product of hotel and room and only those rows are selected where hotel number
is same in both tables. It simulates a join between hotel and room based on hotelnumber
and returns all hotels and their room details
B. Generate the relational algebra for the following queries:
a. List all single rooms with a price below $20 per night
ΠroomNo,type,price(σprice<20 (Room))
b. List the price and type of all rooms at The Ritz hotel
ΠroomNo,price,type (σhotel.name=’The Ritz Hotel’ (σHotel.hotelNo = Room.hotelNo (room x hotel)))
Considering the relational schema provided in Q1., write SQL queries to extract the following information;
A. List all double or family rooms priced below $40 per night, in ascending order
B. How many hotels are listed?
C. Update the price of all rooms of “Avari Hotel” by 10%
D. Insert a new hotel that has only 2 rooms.
E. What is the average price of the room?
F. List the details of all rooms at the “Hilton Hotels”, including the name of the guest staying in the room if
the room is occupied.
G. List the rooms, their type and price that are unoccupied at the “Hilton Hotels”
H. What is the total income from bookings at the “Ritz hotels” today
I. Change the table of guests so that their phone number can be stored as well.
J. List the names of those hotels which offer rooms below the average price of rooms.