You are on page 1of 1

CS122A: Introduction to Data Management Spring 2018

Quiz 5: Relational Algebra _______________________________


Initial Score (out of 10)
Taken by: _______________________________________________ _______________________________
Name Student ID
● We will discuss the answers right after the quiz.
● You are to self-grade and record your actual ​initial​ score (above) as we do so.

1) Consider the following schema, where the key field(s) are underlined (e.g. ​sid ​is the key
for Supplier), and the domain of each field is listed after the italicized field name. The
Catalog relation lists the prices charged for parts by Suppliers. Write the following queries
in relational algebra. (2 pts. each)

Suppliers (​sid​: integer​, ​sname​: string, ​address​: string)


Parts (​pid​: integer​, ​pname​: string, ​color​: string)
Catalog (​sid​: integer, ​pid​: integer​, ​cost​: decimal(8,2))

1.1) Find the ​sids​ of suppliers who supply some green part.
π ​sid​ (( π ​pid​ σ ​color='green'​ Parts) ⨝ Catalog)

1.2) Find the ​sids​ of suppliers who supply some red part or are located at ‘122B Baker St.’
(​π​ ​sid​ ((​π​ ​pid​ ​σ​ ​color='red'​ ​Parts​) ⨝ ​Catalog​)) ​∪​ (​π​ ​sid​ ​σ​ ​address='122B Baker St.'
Suppliers​)

1.3) Find the sids of suppliers who supply every purple part. (​Hint​: ​use division)
(​π​ ​sid​, ​pid​ ​Catalog​)/(​π​ ​pid​ ​σ​ ​color='purple'​ ​Parts​)

2) Consider the Supplier-Parts-Catalog schema from the previous question. State what the
following queries compute. (2 pts. each)

2.1) ​π​ ​sname ​(​π​ ​sid ​((​σ​ ​color='red' P


​ arts​)​ ​⨝ ​(​σ​ cost<100 ​Catalog))​ ​⨝ Suppliers​)

Find the names of the suppliers who supply a red part that costs less than $100.

2.2) ​(​π​ ​sid ​((​σ​ ​color='red' ​Parts​)​ ​⨝ ​(​σ​ cost<100 ​Catalog​)))​ ​ ​∩


​ (​π​ ​sid ​((​σ​ ​color='green' ​Parts​)​ ​⨝ ​(​σ​ cost<100 ​Catalog​)))

Find the sids of the suppliers who supply a red part that costs less than $100 AND a
green part that costs less than $100.

You might also like