Relational Foundations

Keys and Identity

A candidate key is a minimal set of attributes whose values uniquely identify every tuple in a relation. Primary keys are selected candidate keys, while superkeys, alternate keys, foreign keys, and surrogate identifiers serve distinct purposes.
  • A superkey is unique; a candidate key is both unique and irreducible.
  • A relation may have several candidate keys; choosing one as primary does not make the others cease to express identity.
  • Minimal means no proper subset is a superkey, not “fewest columns among all keys.”
  • A natural key derives from the problem domain; a surrogate key is introduced by the system and still needs domain uniqueness constraints where duplicates are forbidden.
  • A foreign key expresses inclusion of referencing values in a referenced key and therefore models a relationship, not local tuple identity.
  • Good identifiers are stable, mandatory, and independent of mutable descriptive data.

Worked candidate-key derivation

Consider ENROLLMENT(student_id, email, course_id, term, grade) with business rules student_id → email, email → student_id, and (student_id, course_id, term) → grade. A student can take the same course in different terms, and many students share a course and term.

Attribute-closure reasoning
Start withClosure under the stated rulesConclusion
{student_id, course_id, term}Adds email, then grade; reaches all five attributesSuperkey
Remove student_id{course_id, term}; cannot obtain student or gradeStudent component is necessary
Remove course_idIdentifies a student and term, but not which enrollmentCourse component is necessary
Remove termIdentifies a student and course, but not a particular offeringTerm component is necessary
Replace student_id with email{email, course_id, term} obtains student_id and gradeA second candidate key