Skip to content
We areTOP 1%

What are super, candidate, primary, alternate and composite keys?

EasyConceptKeys & Constraints
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A key is a set of one or more columns used to identify rows in a table. The different names describe how minimal the set is and how it is used.

  • Super key: any set of columns whose values are unique for every row.
  • Candidate key: a minimal super key; removing any column from it breaks uniqueness.
  • Primary key: the candidate key chosen as the main identifier; it can never be NULL. The remaining candidate keys are alternate keys.
  • Composite key: a key made of two or more columns.

Example: students(roll, email, name)

roll | email     | name
1    | a@clg.edu | Asha
2    | r@clg.edu | Ravi
3    | k@clg.edu | Asha
  • Super keys include {roll}, {email}, {roll, name} and {roll, email}; {name} alone is not one, because Asha repeats.
  • Candidate keys: {roll} and {email}; {roll, name} is not minimal.
  • Primary key: {roll}; alternate key: {email}.
  • In enrolments(roll, course_id), the composite key is (roll, course_id).

More in Keys & Constraints

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account