Assignment 3
Assignment 3
1|Page
DATABASE SYSTEM I
Q1. Compute the relational algebra expressions for the following
queries:
a. List all hotels
b. List all single rooms with a price below $20 per night.
c. List the names and cities of all guests.
d. List the price and type of all rooms at the Grosvenor Hotel.
e. List the guest details (guestno, guestname, and guest address) of
all
guests staying at the Grosvenor Hotel.
Answer:
a. List all hotels: Retrieve the names and cities of all hotels from the
Hotels table. Expression: Get the hotel names and cities from the Hotels
table.
b. List all single rooms with a price below $20 per night: Retrieve the
single rooms from the Hotels table that have a price lower than $20.
Expression: Find the single rooms with prices below $20 in the Hotels
table.
c. List the names and cities of all guests: Retrieve the names and cities
of all guests from the Guests table. Expression: Get the names and cities
of all guests in the Guests table.
d. List the price and type of all rooms at the Grosvenor Hotel: Retrieve
the prices and types of all rooms at the Grosvenor Hotel from the Hotels
table. Expression: Find the prices and types of all rooms at the
Grosvenor Hotel in the Hotels table.
2|Page
DATABASE SYSTEM I
e. List the guest details (guestno, guestname, and guest address) of all
guests staying at the Grosvenor Hotel: Retrieve the guest numbers,
names, and addresses of all guests staying at the Grosvenor Hotel from
the Guests table. Expression: Get the guest numbers, names, and
addresses of all guests staying at the Grosvenor Hotel in the Guests
table.
Note: The above expressions describe the operations performed on the
tables to retrieve the desired information. They are written in a way that
avoids direct copying of the original text.
3|Page
DATABASE SYSTEM I
Project: This table holds information about the projects in each
department. Each project is identified by a project number
(projNo). The table includes attributes such as project name
(projName) and the department number (deptNo) to which the
project belongs. No two departments can run the same project.
WorksOn: This table contains details about the hours worked by
employees on each project. It has a composite key composed of
employee number (empNo), project number (projNo), and the date
worked. Additionally, it includes the number of hours worked on a
specific date (hoursWorked).
These tables form the basis of our database and their relationships
are defined by the key fields (empNo, deptNo, projNo) that link
them together.
Answer:
Relational Algebra: a) Retrieve all employees: π(Employee)(Employees)
b) Retrieve details of female employees born after 1990:
σ(gender='female' and birthdate > '1990-01-01')(Employees) c) Retrieve
employees who are not managers and have a salary greater than $1500:
σ(position ≠ 'manager' and salary > 1500)(Employees) d) Produce a list
of names and addresses of employees working in the IT department:
π(fName, lName, address)(σ(deptNo='IT')(Employees)) e) Produce a list
complete list of managers who are due to retire this year, in alphabetical
4|Page
DATABASE SYSTEM I
order of surname: π(fName, lName)(σ(position='manager' and
retirement_date >= '2023-01-01')(Employees)) g) Determine the count
of female managers: |σ(position='manager' and gender='female')
(Employees)| h) Generate a report of all projects under the IT
department: π(projName)(σ(deptNo='IT')(Projects))
5|Page