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

Assignment 3

The document contains assignments related to relational algebra expressions for various queries about hotels and employees in a database system. It includes tasks such as listing hotels, room types, guest details, and employee reports based on specific criteria. The document also outlines the structure of the database tables and provides relational algebra, tuple relational calculus, and domain relational calculus expressions for the queries.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 3

The document contains assignments related to relational algebra expressions for various queries about hotels and employees in a database system. It includes tasks such as listing hotels, room types, guest details, and employee reports based on specific criteria. The document also outlines the structure of the database tables and provides relational algebra, tuple relational calculus, and domain relational calculus expressions for the queries.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DATABASE SYSTEM I

Name: Sirajuddin Kamal


Reg: FA21-BCS-221
Submitted To: Maria Gul
Date Of Submission:17-June-2023
Assignment No:03

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.

Q2. Construct by using relational algebra, produce a report of all


employees from the IT and planning departments who are born
after 1990.
We have a database in a relational database management system
(RDBMS) that consists of the following tables:
Employee: This table contains information about the employees.
Each employee is uniquely identified by their employee number
(empNo). The table includes attributes such as first name (fName),
last name (lName), address, date of birth (DOB), gender (sex),
position, and department number (deptNo).
Department: This table stores details about the different
departments in the organization. Each department is identified by a
department number (deptNo). The table also includes the
department name (deptName) and the employee number
(mgrEmpNo) of the manager for that department. There is only one
manager for each department.

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

(Employees ⨝ WorksOn ⨝ σ(projName='SCCS')(Projects)) f) Retrieve a


of names of employees working on the SCCS project: π(fName, lName)

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))

Tuple Relational Calculus: a) {e | ∃e ∈ Employees} b) {e | ∃e ∈


Employees ∧ (e.gender = 'female' ∧ e.birthdate > '1990-01-01')} c) {e |
∃e ∈ Employees ∧ (e.position ≠ 'manager' ∧ e.salary > 1500)} d)
{e.fName, e.lName, e.address | ∃e ∈ Employees ∧ (e.deptNo = 'IT')} e)
{e.fName, e.lName | ∃e ∈ Employees ∧ (∃w ∈ WorksOn ∧ (e.empNo
= w.empNo ∧ w.projNo IN (σ(projName='SCCS')(Projects))))} f)
{e.fName, e.lName | ∃e ∈ Employees ∧ (e.position = 'manager' ∧
e.retirement_date >= '2023-01-01')} g) |{e | ∃e ∈ Employees ∧
(e.position = 'manager' ∧ e.gender = 'female')}| h) {p.projName | ∃p ∈
Projects ∧ (p.deptNo = 'IT')}

Domain Relational Calculus: a) {e | ∃e ( Employees(e) )} b) {e | ∃e


( Employees(e) ∧ (e.gender = 'female' ∧ e.birthdate > '1990-01-01') )}
c) {e | ∃e ( Employees(e) ∧ (e.position ≠ 'manager' ∧ e.salary >
1500) )} d) {e | ∃e ( Employees(e) ∧ (e.deptNo = 'IT') )} e) {e | ∃e
( Employees(e) ∧ (∃w ( WorksOn(w) ∧ (e.empNo = w.empNo ∧ ∃p
( Projects(p) ∧ (w.projNo = p.projNo ∧ p.projName = 'SCCS') ) ) ) ) )}
f) {e | ∃e ( Employees(e) ∧ (e.position = 'manager' ∧ e.retirement_date
>= '2023-01-01') )} g) |{e | ∃e ( Employees(e) ∧ (e.position = 'manager'
∧ e.gender = 'female') )}| h) {p | ∃p ( Projects(p) ∧ (p.deptNo = 'IT') )}

5|Page

You might also like