DBMS Keys Explained for GATE

Learn all types of DBMS keys including Super Key, Candidate Key, Primary Key, Foreign Key and Composite Key with examples and clear explanations.

What is a Key in DBMS?

In DBMS, a key is an attribute or set of attributes used to uniquely identify a record in a table.

Keys are very important because:

1. Candidate Key

A Candidate Key is a minimal set of attributes that can uniquely identify a record in a table.

👉 Candidate Key = Unique + Minimal

🧠 Simple Understanding

A candidate key is a super key with no extra attributes. If we remove any attribute from it, it will lose uniqueness.

⚡ Key Points

📊 Example Table

STUD_NO NAME PHONE
101 Amit 9876
102 Ravi 9123

🔍 Analysis

👉 So Candidate Keys are:
  • ✔ STUD_NO
  • ✔ PHONE (if unique)

❗ Important Concept (Minimality)

A key is called minimal if removing any attribute makes it NOT unique.

Example:

🤯 Confusion Example (Combination Case)

NAME PHONE
Amit9876
Amit9123
Ravi9876

🔍 Analysis

👉 (NAME, PHONE) is a Candidate Key because:
  • ✔ It is unique
  • ✔ It is minimal (cannot remove anything)

🎯 GATE Point

✔ Candidate Key = Minimal Super Key
✔ There can be multiple candidate keys in a table

💣 Golden Rule

If a key has extra attributes → Not a Candidate Key

2. Super Key

Super Key Diagram

A Super Key is a set of one or more attributes that can uniquely identify a record in a table.

👉 If any combination of columns uniquely identifies a row → it is a Super Key

🧠 Simple Understanding

Even if extra attributes are added, the key is still valid as long as uniqueness is maintained.

⚡ Key Points

📊 Example Table

STUD_NO NAME PHONE
101 Amit 9876
102 Ravi 9123

✅ Possible Super Keys

❗ Important Concept

If one attribute is already unique, adding more attributes will still keep it unique.

🎯 GATE Point

✔ Every Candidate Key is a Super Key

❌ But every Super Key is NOT a Candidate Key

🔥 Understanding Uniqueness (Most Important Concept)

In DBMS, before deciding any key, we must understand uniqueness.

👉 Unique means: No two rows have the same value (or combination of values)

❌ Case 1: Not Unique

NAME PHONE
Amit9876
Ravi9876

PHONE is repeated → ❌ Not Unique → Not a key

❓ Why Phone Number Can Repeat?

Many students think that phone numbers are always unique, but in databases this is NOT always true.

👉 In DBMS, we NEVER assume a field is unique unless it is clearly given.

❌ Case 2: Not Unique

NAME PHONE
Amit9876
Amit9123

NAME is repeated → ❌ Not Unique

✅ Case 3: Unique

NAME PHONE
Amit9876
Ravi9123

Both NAME and PHONE are unique → ✅ Can be keys

🤯 Case 4: Combination Becomes Unique

NAME PHONE
Amit9876
Amit9123
Ravi9876

🔍 Analysis

👉 So (NAME, PHONE) is:
  • ✔ Super Key
  • ✔ Candidate Key (because minimal)

🧠 How to Check Uniqueness (Exam Method)

  1. Pick a column
  2. Check if values repeat
  3. If repeat → Not unique
  4. If not repeat → Unique
  5. If not unique → try combinations

💣 Golden Rule

If even one duplicate exists → Not unique

3. Primary Key

A Primary Key is a candidate key that is selected to uniquely identify each record in a table.

👉 Primary Key = Selected Candidate Key

🧠 Simple Understanding

There can be multiple candidate keys in a table, but only one is chosen as the primary key.

⚡ Key Points

📊 Example Table

STUD_NO EMAIL PHONE
101 amit@gmail.com 9876
102 ravi@gmail.com 9123

🔍 Analysis

👉 From these, one is selected as Primary Key:
  • ✔ STUD_NO → Primary Key

❗ Important Concept

A primary key is chosen based on reliability and simplicity.

🤯 Confusion Example

If multiple candidate keys exist, which one becomes primary key?

👉 The one that is:
  • ✔ Stable (does not change)
  • ✔ Simple
  • ✔ Reliable

🎯 GATE Point

✔ Primary Key is always a Candidate Key
✔ But not all Candidate Keys are Primary Keys

💣 Golden Rule

Primary Key cannot be NULL and must be unique.

4. Foreign Key

A Foreign Key is an attribute in one table that is used to link it with another table.

👉 Foreign Key = Link between two tables

🧠 Simple Understanding

A foreign key in one table refers to the primary key of another table.

⚡ Key Points

📊 Example (Two Tables)

Table 1: STUDENT

STUD_ID (PK) NAME
101 Amit
102 Ravi

Table 2: COURSE

COURSE_ID STUD_ID (FK)
C1 101
C2 102

🔍 Analysis

👉 Foreign Key connects COURSE table to STUDENT table

❗ Important Concept (Referential Integrity)

A foreign key must match a value in the parent table (or be NULL).

🤯 Confusion Point

Can foreign key have duplicates?

👉 YES! Multiple rows can refer to the same parent record

🎯 GATE Point

✔ Foreign Key can have duplicates
✔ Foreign Key can be NULL
✔ Maintains relationship between tables

💣 Golden Rule

Foreign Key must match a Primary Key value (or be NULL)

5. Composite Key

A Composite Key is a key formed by combining two or more attributes to uniquely identify a record.

👉 Composite Key = Combination of columns used as a key

🧠 Simple Understanding

When a single column is not enough to uniquely identify records, we combine multiple columns to form a composite key.

⚡ Key Points

📊 Example Table

STUD_ID COURSE_ID MARKS
101 C1 85
101 C2 90
102 C1 88

🔍 Analysis

👉 So (STUD_ID, COURSE_ID) is a Composite Key

❗ Important Concept

Composite Key is used when no single attribute can uniquely identify a record.

🎯 GATE Point

✔ Composite Key can also be a Candidate Key
✔ It can be selected as Primary Key

💣 Golden Rule

If single attributes fail → try combination → Composite Key

Difference Between Keys

📊 Comparison of Keys

Key Type Unique Minimal NULL Allowed
Super Key
Candidate Key
Primary Key
Foreign Key
Composite Key

GATE Important Points

Conclusion

DBMS keys are the foundation of database design. Understanding keys is very important before studying Functional Dependency and Normalization.

🚀 Continue Learning

Move to the next topic: Functional Dependency

👉 Next Topic: Functional Dependency →

🔗 Related Topics