18 Chapter 3
key, not something that only might be a key. The instance shown is just one possible
“snapshot” of the relation. At other times, the same relation may have an instance (or
snapshot) that contains a totally different set of tuples, and we cannot make predictions
about those instances based only upon the instance that we are given.
Exercise 3.6 What is a foreign key constraint? Why are such constraints important?
What is referential integrity?
Answer 3.6 Answer omitted.
Exercise 3.7 Consider the relations Students, Faculty, Courses, Rooms, Enrolled,
Teaches, and Meets In defined in Section 1.5.2.
1. List all the foreign key constraints among these relations.
2. Give an example of a (plausible) constraint involving one or more of these relations
that is not a primary key or foreign key constraint.
Answer 3.7 There is no reason for a foreign key constraint (FKC) on the Students,
Faculty, Courses, or Rooms relations. These are the most basic relations and must be
free-standing. Special care must be given toenteringdataintothesebaserelations.
In the Enrolled relation, sid and cid should both have FKCs placed on them. (Real
students must be enrolled in real courses.) Also, since real teachers must teach real
courses, both the fid and the cid fields in the Teaches relation should have FKCs.
Finally, Meets In should place FKCs on both the cid and rno fields.
It would probably be wise to enforce a few other constraints on this DBMS: the length
of sid,cid,andfid could be standardized; checksums could be added to these iden-
tification numbers; limits could be placed on the size of the numbers entered into the
credits, capacity, and salary fields; an enumerated type should be assigned to the grade
field (preventing a student from receiving a grade of G, among other things); etc.
Exercise 3.8 Answer each of the following questions briefly. The questions are based
on the following relational schema:
Emp(eid: integer,ename: string,age: integer,salary: real)
Works(eid: integer,did: integer,pcttime: integer)
Dept(did: integer,dname: string,budget: real,managerid: integer)
1. Give an example of a foreign key constraint that involves the Dept relation. What
are the options for enforcing this constraint when a user attempts to delete a Dept
tuple?