4
RELATIONAL ALGEBRA AND
CALCULUS
Exercise 4.1 Explain the statement that relational algebra operators can be com–
posed. Why is the ability to compose operators important?
Answer 4.1 Every operator in relational algebra accepts one or more relation in-
stances as arguments and the result is always an relation instance. So the argument
of one operator could be the result of another operator. This is important because,
this makes it easy to write complex queries by simply composing the relational algebra
operators.
Exercise 4.2 Given two relations R1andR2, where R1 contains N1 tuples, R2con–
tains N2 tuples, and N2 >N1 >0, give the minimum and maximum possible sizes (in
tuples) for the resulting relation produced by each of the following relational algebra
expressions. In each case, state any assumptions about the schemas for R1andR2
needed to make the expression meaningful:
(1) R1∪R2, (2) R1∩R2, (3) R1−R2, (4) R1×R2, (5) σa=5(R1), (6) πa(R1),
and (7) R1/R2
Answer 4.2 Answer omitted.
Exercise 4.3 Consider the following schema:
Suppliers(sid: integer,sname: string,address: string)
Parts(pid: integer,pname: string,color: string)
Catalog(sid: integer,pid: integer,cost: real)
The key fields are underlined, and the domain of each field is listed after the field
name. Therefore sid is the key for Suppliers, pid is the key for Parts, and sid and pid
together form the key for Catalog. The Catalog relation lists the prices charged for
parts by Suppliers. Write the following queries in relational algebra, tuple relational
calculus, and domain relational calculus:
28