Now let’s consider some reasonably realistic examples of relvars with more than one key. The first concerns a relvar EXAM, with attributes S (student), J (subject), and P (position), and predicate *Student S was examined in subject J and achieved position P in the class list*. For the sake of the example, let’s assume there are no ties (that is, no two students obtained the same position in the same subject). Then, clearly, given a student and subject, there’s exactly one corresponding position; equally, given a subject and position, there’s exactly one corresponding student. So the FDs {S,J} → {P} and {J,P} → {S} both hold, and {S,J} and {J,P} are both keys (or candidate keys, if you prefer):

EXAM { S , J , P } KEY { S , J } KEY { J , P }

Here’s another example (it’s basically Exercise 13.6 from Chapter 13): We’re given a relvar representing marriages, with attributes A, B, and C and predicate *Person A married person B on date C*. Assuming no polygamy, and assuming also that no two persons marry each other more than once, every pair of attributes here is a key:

MARRIAGE { A , B , C } KEY { A , B } KEY { B , C } KEY { C , A }

And here’s yet another example, based on a simple airline application (the predicate is *Pilot PILOT takes a flight out from gate GATE at hour HOUR on day DAY*):

ROSTER { DAY , HOUR , GATE , PILOT } KEY { DAY , HOUR , GATE } KEY { DAY , HOUR , PILOT }

How do we choose the primary key in cases such as these? What grounds are there for ...

Start Free Trial

No credit card required