Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
MySQL + SQL · Lesson 19

Candidate, Super and Alternate Key in DBMS

In this lesson: Difference between super key, candidate key and alternate key in DBMS with one table example and comparison chart.

How these keys relate

Super, candidate, primary and alternate keys sound similar but form a clear hierarchy. Super keys are the broadest, candidate keys narrow them down, one candidate becomes the primary key, and the rest become alternate keys. Understanding the order makes them easy.

💡 Super keys → candidate keys (minimal) → one primary key + the rest as alternate keys.

Super key

A super key is any set of columns that can uniquely identify a row — even if it has extra columns. For a students table where roll is unique, all of these are super keys:

{roll}
{roll, name}
{roll, name, marks}

Each uniquely identifies a row, but the last two carry unneeded columns.

Candidate key

A candidate key is a minimal super key — no extra columns. From the super keys above, only {roll} is a candidate key, because removing any column would break uniqueness. A table can have several candidate keys.

Primary key

The primary key is the one candidate key you choose as the official identifier. It cannot be null and there is only one per table.

CREATE TABLE students (
    roll INT PRIMARY KEY,
    email VARCHAR(100) UNIQUE
);

Here roll is chosen as the primary key.

Alternate key

An alternate key is a candidate key that was not chosen as the primary key. In the table above, if both roll and email can identify a student, and roll is primary, then email is the alternate key. It still uniquely identifies rows.

A worked example

A students table with roll, email, name, marks, where both roll and email are unique:

  • Super keys: {roll}, {email}, {roll, name}, {roll, email}, and many more.
  • Candidate keys: {roll} and {email} (both minimal).
  • Primary key: {roll} (chosen).
  • Alternate key: {email} (the other candidate).

Common mistakes

  • Calling every super key a candidate key. Only minimal super keys qualify.
  • Thinking there is one candidate key. A table can have several.
  • Forgetting alternate keys. The unchosen candidate keys are alternate keys.
  • Confusing primary and candidate. Primary is the chosen candidate key.

Summary

  • A super key identifies a row, possibly with extra columns.
  • A candidate key is a minimal super key (no extras).
  • The primary key is the chosen candidate key, never null.
  • Alternate keys are the candidate keys not chosen as primary.
  • The order: super → candidate → primary + alternate.

Next, see all key types in keys in DBMS explained, or the two most used in primary key vs foreign key.

Frequently Asked Questions

What is the difference between a super key and a candidate key?
A super key is any set of columns that uniquely identifies a row, even with extra unneeded columns. A candidate key is a minimal super key — one with no extra columns. Every candidate key is a super key, but not every super key is a candidate key.
What is an alternate key?
An alternate key is a candidate key that was not chosen as the primary key. If a table has several candidate keys, you pick one as primary, and the rest become alternate keys. They still uniquely identify rows.
What is the difference between a candidate key and a primary key?
Candidate keys are all the minimal keys that could serve as the unique identifier. The primary key is the one candidate key you actually choose. So the primary key is always a candidate key, but a table can have several candidate keys.
Can a table have multiple candidate keys?
Yes. For example, a student table might have both a roll number and a unique email, each able to identify a student. Both are candidate keys; you choose one as the primary key and the other becomes an alternate key.
How do super, candidate, primary and alternate keys relate?
Super keys are the broadest set. Candidate keys are the minimal super keys. From the candidate keys, one is chosen as the primary key, and the remaining candidate keys are called alternate keys.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicComposite Key and Unique Key Your progress: 19 / 151 (13%) · Lesson 20 / 151 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free