2
2
2
2
Introdu tion to the Relational
Model
2.2 Consider the foreign-key onstraint from the dept name attribute of instru tor to
the department relation. Give examples of inserts and deletes to these relations
that an ause a violation of the foreign-key onstraint.
Answer:
Inserting a tuple:
(10111, Ostrom, E onomi s, 110000)
5
6 Chapter 2 Introdu tion to the Relational Model
into the instru tor table, where the department table does not have the de-
partment E onomi s, would violate the foreign-key onstraint.
Deleting the tuple:
(Biology, Watson, 90000)
from the department table, where at least one student or instru tor tuple
has dept name as Biology, would violate the foreign-key onstraint.
2.3 Consider the time slot relation. Given that a parti ular time slot an meet more
than on e in a week, explain why day and start time are part of the primary key
of this relation, while end time is not.
Answer:
The attributes day and start time are part of the primary key sin e a parti ular
lass will most likely meet on several di erent days and may even meet more
than on e in a day. However, end time is not part of the primary key sin e a
parti ular lass that starts at a parti ular time on a parti ular day annot end at
more than one time.
2.4 In the instan e of instru tor shown in Figure 2.1, no two instru tors have the
same name. From this, an we on lude that name an be used as a superkey
(or primary key) of instru tor?
Answer:
No. For this possible instan e of the instru tor table the names are unique, but
in general this may not always be the ase (unless the university has a rule that
two instru tors annot have the same name, whi h is a rather unlikey s enario).
2.5 What is the result of rst performing the Cartesian produ t of student and advi-
sor , and then performing a sele tion operation on the result with the predi ate
The result attributes in lude all attribute values of student followed by all at-
tributes of advisor. The tuples in the result are as follows: For ea h student who
has an advisor, the result has a row ontaining that student's attributes, followed
by an s id attribute identi al to the student's ID attribute, followed by the i id
attribute ontaining the ID of the students advisor.
Students who do not have an advisor will not appear in the result. A student
who has more than one advisor will appear a orresponding number of times
in the result.
2.6 Consider the employee database of Figure 2.17. Give an expression in the rela-
tional algebra to express ea h of the following queries:
a. Find the name of ea h employee who lives in ity Miami.
Pra ti e Exer ises 7
(
bran h bran h name , bran h ity, assets )
ustomer (ID, ustomer name , ustomer street, ustomer ity )
loan(loan number, bran h name, amount)
borrower (ID, loan number)
a ount (a ount number , bran h name, balan e)
Answer:
Answer:
loan )).
2.8 Consider the employee database of Figure 2.17. Give an expression in the rela-
tional algebra to express ea h of the following queries:
a. Find the ID and name of ea h employee who does not work for BigBank.
b. Find the ID and name of ea h employee who earns at least as mu h as
every employee in the database.
Answer:
a. To nd employees who do not work for BigBank, we rst nd all those
who do work for BigBank. Those are exa tly the employees not part of the
8 Chapter 2 Introdu tion to the Relational Model
desired result. We then use set di eren e to nd the set of all employees
minus those employees that should not be in the result.
: : BigBank
¨¨ (works)))
: , :
employee
: < B:salary employee ))
2.9 The division operator of relational algebra, , is dened as follows. Let r(R)
and s(S) be relations, and let S Ó R; that is, every attribute of s hema S is
also in s hema R. Given a tuple t, let t[S℄ denote the proje tion of tuple t on
the attributes in S. Then r s is a relation on s hema R * S (that is, on the
s hema ontaining all attributes of s hema R that are not in s hema S). A tuple
t is in r s if and only if both of two onditions hold:
tis in R*S (r)
For every tuple ts in s, there is a tuple tr in r satisfying both of the following:
a. tr [S℄ = t
s [S ℄
b. tr [R * S ℄ = t
Answer:
r } ID ourse id ( )
,
takes
To see that this expression is true, we observe that R*S (r) gives us all
tuples t that satisfy the rst ondition of the denition of division. The
expression on the right side of the set di eren e operator
serves to eliminate those tuples that fail to satisfy the se ond ondition of
the denition of division. Let us see how it does so. Consider R*S (r) s.
This relation is on s hema R, and pairs every tuple in R*S (r) with every
tuple in s. The expression R*S S (r) merely reorders the attributes of r.
Thus, (R*S (r) s) * R*S S (r) gives us those pairs of tuples from
,
then there is some tuple ts in s that does not ombine with tuple tj to form
a tuple in r. Thus, tj holds a value for attributes R * S that does not appear
in r s. It is these values that we eliminate from R*S (r).