Candidate Key

A candidate key is a minimal set of attributes that uniquely identifies every tuple in a relation. “Minimal” means no proper subset of the candidate key is also unique. A relation can have multiple candidate keys — one is chosen as the Primary Key, the rest become alternate keys.

Example

In a students table with columns (id, email, ssn, name):

  • {id} — Candidate key (unique, minimal)
  • {email} — Candidate key (unique, minimal)
  • {ssn} — Candidate key (unique, minimal)
  • {id, email}Not a candidate key (not minimal — {id} alone is sufficient)
  • {name}Not a candidate key (not unique)

Choose {id} as Primary Key; {email} and {ssn} become alternate keys.

Finding Candidate Keys

Using attribute closure: compute X⁺ for every possible attribute set X. If X⁺ = all attributes and no proper subset of X has this property, X is a candidate key.

Key Hierarchy

graph TD
    SK[Superkey] --> CK[Candidate Key]
    CK --> PK[Primary Key]
    CK --> AK["Alternate Key"]
  • Superkey — Any set of attributes that uniquely identifies tuples (may have extra attributes)
  • Candidate Key — A minimal Superkey
  • Primary Key — The chosen candidate key
  • Alternate Key — Candidate keys not chosen as primary