⭐ 1. PRIMARY KEY (PK)
✔ Definition:
A Primary Key is a column (or set of columns) that uniquely identifies each row in a table.
✔ Important points:
- Unique + Not Null
- A table can have only ONE primary key.
- No two rows can have the same primary key value.
- PK ensures entity integrity.
✔ Example Table: Student
| StudentID | Name | Class |
|---|---|---|
| 101 | Raj | 10 |
| 102 | Asha | 10 |
| 103 | Ravi | 9 |
- Here StudentID is the Primary Key because it uniquely identifies each student.
✔ Primary Key = Unique + Not Null
⭐ 2. FOREIGN KEY (FK)
✔ Definition:
A Foreign Key is a column that creates a link/relationship between two tables.
It references the Primary Key of another table.
✔ Important points:
- Maintains Referential Integrity
- Foreign key can have duplicate values
- Foreign key can be NULL
- It represents a relationship between tables (1-to-Many or Many-to-Many)
✔ Example: Student & Marks Tables
Student Table
| StudentID (PK) | Name |
|---|---|
| 101 | Raj |
| 102 | Asha |
Marks Table
| MarkID | StudentID (FK) | Subject | Marks |
|---|---|---|---|
| 1 | 101 | Math | 90 |
| 2 | 101 | English | 85 |
| 3 | 102 | Math | 88 |
- StudentID in Marks is a Foreign Key referencing Primary Key in Student table.
✔ FK ensures:
➡ The value must exist in the parent table (or be NULL)
➡ Prevents invalid references
⭐ 3. CANDIDATE KEY
✔ Definition:
A Candidate Key is a column (or set of columns) that can uniquely identify each row in a table.
✔ Important points:
- A table can have multiple candidate keys.
- These are possible choices for the Primary Key.
- From the candidate keys, one is chosen as the Primary Key.
✔ Example:
| Aadhaar | PAN | Mobile | Name |
|---|---|---|---|
| 1111 | AB12 | 9999 | Raj |
In this table:
- Aadhaar
- PAN
- Mobile
All three can uniquely identify a person →
So all three are Candidate Keys.
But table will choose one of them as the Primary Key (e.g., Aadhaar).
⭐ 4. COMPOSITE KEY
✔ Definition:
A Composite Key is a key formed by two or more columns together to uniquely identify a record.
A single column is not enough.
✔ Example: Attendance Table
| StudentID | Date | Status |
|---|---|---|
| 101 | 01-01-2024 | Present |
| 101 | 02-01-2024 | Absent |
| 102 | 01-01-2024 | Present |
- StudentID alone is not unique.
- Date alone is not unique.
- But StudentID + Date together uniquely identify each row.
👉 Composite Key = Multiple columns + Unique together
⭐ 5. SUPER KEY
✔ Definition:
A Super Key is any combination of columns that can uniquely identify a row.
✔ Important points:
- Super keys are supersets of Candidate Keys.
- Every Candidate Key is a Super Key,
but every Super Key is NOT a Candidate Key. - Super keys may have extra/unnecessary attributes.
✔ Example:
| EmployeeID | Mobile | Name | |
|---|---|---|---|
| 01 | *@*.com | 9999 | Raj |
Candidate keys:
- EmployeeID
- Mobile
Possible super keys:
- EmployeeID
- Mobile
- (EmployeeID + Email)
- (EmployeeID + Email + Mobile + Name)
✔ As long as the combination uniquely identifies a record → it is a Super Key.
📌 Difference Table
| Key Type | Uniqueness | Null Allowed | How Many in a Table? | Purpose |
|---|---|---|---|---|
| Primary Key | Yes | ❌ No | Only 1 | Unique row identification |
| Foreign Key | No | ✔ Yes | Many | Link between tables |
| Candidate Key | Yes | ❌ No | Many | Possible choices for PK |
| Composite Key | Columns together | ❌ No | Many | Unique combination |
| Super Key | Yes | ✔ Yes | Many | Any unique identifier (may have extra fields) |
🧠 Easiest Way to Remember
✔ Primary Key → “Main key” (only ONE)
✔ Foreign Key → “Link key” (connects tables)
✔ Candidate Key → “Possible primary keys”
✔ Composite Key → “Multiple columns = one key”
✔ Super Key → “Super set of Candidate Key”
🔥 Examples (VERY IMPORTANT)
Example 1: Employee Table
| EmpID | PAN | Mobile | Name |
|---|
- Primary Key: EmpID
- Candidate Keys: EmpID, PAN, Email, Mobile
- Composite Key: (Email + Mobile)
- Super Keys: EmpID, PAN, Email, Mobile, (EmpID + Name), (Email + Mobile + Name)
- Foreign Key: Not present in this table
Example 2: Order Table
Orders Table
| OrderID (PK) | CustomerID (FK) | Amount |
|---|---|---|
| 01 | C01 | 500 |
Customers Table
| CustomerID (PK) | Name |
|---|---|
| C01 | Raj |
- CustomerID in Orders is a Foreign Key
- CustomerID in Customers is a Primary Key
📝 SHORT ONE-LINER DEFINITIONS
- Primary Key: Unique + Not Null identifier.
- Foreign Key: Refers to primary key of another table.
- Candidate Key: All possible unique identifiers.
- Composite Key: Key made of multiple columns.
- Super Key: Any unique combination (includes extra attributes).
✅ MCQs on Primary, Foreign, Candidate, Composite & Super Key
🔶 SECTION A: PRIMARY KEY
1. A Primary Key must be:
A. Unique only
B. Not Null only
C. Unique and Not Null
D. Nullable
Answer: C
2. How many Primary Keys can a table have?
A. Only one
B. Two
C. Unlimited
D. One per row
Answer: A
3. Primary Key ensures which integrity?
A. Domain integrity
B. Referential integrity
C. Entity integrity
D. File integrity
Answer: C
4. Which of the following can be a Primary Key?
A. Mobile number
B. Aadhaar number
C. PAN number
D. All of the above
Answer: D
5. A Primary Key column can have:
A. Duplicate values
B. Null values
C. Only numeric values
D. Only unique and non-null values
Answer: D
🔶 SECTION B: FOREIGN KEY
6. Foreign Key refers to:
A. Another column in same table
B. Primary Key in another table
C. Any random column
D. Composite Key only
Answer: B
7. Which integrity is enforced by Foreign Key?
A. Entity integrity
B. Referential integrity
C. Domain integrity
D. Functional integrity
Answer: B
8. A Foreign Key can be:
A. Null
B. Duplicated
C. Both A and B
D. Neither
Answer: C
9. Foreign Key creates:
A. Redundancy
B. Relationship between tables
C. Table partition
D. Primary Key
Answer: B
10. Which of the following can become a Foreign Key?
A. Primary Key of parent table
B. Any unique attribute
C. Any attribute
D. Only numeric column
Answer: A
🔶 SECTION C: CANDIDATE KEY
11. A Candidate Key is:
A. A super key with extra attributes
B. A possible Primary Key
C. Always composite
D. Always foreign key
Answer: B
12. A table can have:
A. Multiple Candidate Keys
B. Only one Candidate Key
C. No Candidate Key
D. Only two Candidate Keys
Answer: A
13. Candidate Key must be:
A. Unique
B. Not Null
C. Minimal
D. All of the above
Answer: D
14. Which is true?
A. Every Primary Key is a Candidate Key
B. Every Candidate Key is a Primary Key
C. Both A and B
D. None
Answer: A
15. Candidate Key is chosen for:
A. Backup
B. Primary Key
C. Index
D. Foreign Key
Answer: B
🔶 SECTION D: COMPOSITE KEY
16. Composite Key is formed by:
A. Two or more columns
B. Only one column
C. Foreign Key
D. None
Answer: A
17. A Composite Key is used when:
A. One field is not unique
B. All fields are null
C. There is no relationship
D. There is no Primary Key
Answer: A
18. Composite Key always provides:
A. Relationship
B. Uniqueness using combined values
C. Foreign Key
D. Encryption
Answer: B
19. In a sales table, (OrderID + ProductID) can form:
A. Candidate Key
B. Composite Key
C. Super Key
D. All of the above
Answer: D
(Because composite + unique makes it candidate + super key)
20. Composite Primary Key means:
A. Two Primary Keys
B. Two columns together act as Primary Key
C. Two tables share the same key
D. None
Answer: B
🔶 SECTION E: SUPER KEY
21. A Super Key is:
A. Minimal unique identifier
B. Any column(s) that uniquely identify a row
C. Always Primary Key
D. Foreign Key
Answer: B
22. Which is true for Super Key?
A. Every Candidate Key is a Super Key
B. Every Super Key is a Candidate Key
C. Both A and B
D. None
Answer: A
23. Super Key may contain:
A. Extra attributes
B. Only minimal attributes
C. Only one attribute
D. Only numeric values
Answer: A
24. (EmployeeID + Name + Email) is typically a:
A. Primary Key
B. Candidate Key
C. Composite Key
D. Super Key
Answer: D
25. Super Key must be:
A. Unique
B. Minimal
C. Non-unique
D. Used only for linking
Answer: A
🔶 SECTION F: COMPARISON-BASED
26. Which key is always unique and always not null?
A. Foreign Key
B. Composite Key
C. Primary Key
D. Super Key
Answer: C
27. Which key can accept NULL values?
A. Primary Key
B. Super Key
C. Foreign Key
D. Candidate Key
Answer: C
28. Candidate Key vs Super Key – difference?
A. Candidate Key is minimal
B. Super Key may have extra attributes
C. Both A & B
D. None
Answer: C
29. Composite Key must be:
A. A super key
B. A foreign key
C. Always minimal
D. Always primary
Answer: A
30. Primary Key is chosen from:
A. Foreign Keys
B. Candidate Keys
C. Super Keys
D. Composite Keys
Answer: B
🔶 SECTION G: BANKING SCENARIO QUESTIONS
31. In banking, CustomerID is typically a:
A. Foreign Key
B. Composite Key
C. Primary Key
D. Super Key
Answer: C
32. In an Account table, CustomerID is usually a:
A. Primary Key
B. Candidate Key
C. Foreign Key
D. Composite Key
Answer: C
33. In Loan table, (CustomerID + LoanID) can be:
A. Composite Key
B. Candidate Key
C. Super Key
D. All of the above
Answer: D
34. In ATM transactions table, (CardNo + ATMID + TimeStamp) is:
A. Composite Key
B. Candidate Key
C. Unique Composite Key
D. All
Answer: D
🔶 SECTION H: TRUE / FALSE
35. A table can have multiple Primary Keys.
False
36. Every Primary Key is also a Super Key.
True
37. A Foreign Key can be null.
True
38. Composite Key cannot be a Primary Key.
False
39. Candidate Key is always minimal.
True
🔶 SECTION I: ADVANCED / TRICKY MCQs
40. A Super Key with no unnecessary attributes is called:
A. Foreign Key
B. Candidate Key
C. Composite Key
D. Primary Key
Answer: B
41. Which key uniquely identifies a tuple?
A. Foreign Key
B. Candidate Key
C. Super Key
D. Both B & C
Answer: D
42. A Candidate Key with more than one attribute is:
A. Composite Key
B. Super Key
C. Foreign Key
D. Primary Key
Answer: A
43. In a child table, the referenced column must be:
A. Primary Key or Candidate Key
B. Foreign Key
C. Super Key
D. Composite Key
Answer: A
44. Foreign Key prevents:
A. Redundant data
B. Insertion of invalid references
C. Files from deleting
D. Logs from updating
Answer: B
🔶 SECTION J: PRACTICAL TABLE-BASED
45. Given table:
| EmpID | Mobile | Name |
|---|
Which is NOT a Candidate Key?
A. EmpID
B. Email
C. Mobile
D. Name
Answer: D
46. In above table, which is a Super Key?
A. EmpID
B. (EmpID + Name)
C. Both A and B
D. None
Answer: C
47. In Student table, (RollNo + Class) is unique. Then RollNo + Class is a:
A. Super Key
B. Composite Key
C. Candidate Key
D. All of the above
Answer: D
🔶 SECTION K:
48. Minimal Super Key is called:
A. Primary Key
B. Composite Key
C. Candidate Key
D. Foreign Key
Answer: C
49. Which key ensures “no orphan records”?
A. Super Key
B. Primary Key
C. Foreign Key
D. Composite Key
Answer: C
50. Which key can be chosen as the Primary Key?
A. Super Key
B. Candidate Key
C. Foreign Key
D. Optional Key
Answer: B
51. Which key may contain more attributes than necessary?
A. Candidate Key
B. Super Key
C. Primary Key
D. Foreign Key
Answer: B
🔶 SECTION L: EXTRA IMPORTANT
52. Composite Key is always:
A. A Candidate Key
B. A Super Key
C. A Primary Key
D. Both A & B
Answer: B
53. A column that uniquely identifies the record is:
A. Candidate Key
B. Primary Key
C. Super Key
D. All
Answer: D
54. A key that allows duplicate values is:
A. Primary Key
B. Candidate Key
C. Foreign Key
D. Super Key
Answer: C
55. A Super Key + minimal is:
A. Primary Key
B. Candidate Key
C. Foreign Key
D. Composite Key
Answer: B
56. A Primary Key chosen from Candidate Key is based on:
A. User preference
B. Performance
C. Stability of values
D. All of the above
Answer: D
