🔑 1. Simple Key
- A single attribute (column) that uniquely identifies a record.
- Example:
In a Users table, user_id is a simple key if it alone uniquely identifies each user.
user_id: 101, 102, 103
🧩 2. Composite Key
- A combination of two or more attributes that together uniquely identify a record.
- Used when no single column can serve as a unique identifier.
- Example:
In a CourseRegistrations table, the combination of student_id and course_id may form a composite key.
(student_id = 10, course_id = "CS101")
🎯 3. Candidate Key
- Any attribute or combination of attributes that can uniquely identify a row in a table.
- A table can have multiple candidate keys, but only one becomes the primary key.
- Example:
In a Users table:user_id (unique number)email (also unique)
Both are candidate keys.
🔁 4. Alternate Key
- A candidate key that was not chosen as the primary key.
- It is still unique and may be used for lookup purposes.
- Example:
If user_id is the primary key, then email becomes the alternate key.
Summary Table
| Term | Definition |
|---|
| Simple Key | A single attribute that uniquely identifies a record |
| Composite Key | Two or more attributes combined to uniquely identify a record |
| Candidate Key | Any column or combination that can uniquely identify a record |
| Alternate Key | A candidate key not chosen as the primary key |