Careeroza
Keys
Types of Keys
| Key | Definition |
|---|---|
| Super key | any set of columns that uniquely identifies a row |
| Candidate key | a minimal super key (no column can be removed) |
| Primary key | the candidate key chosen as the main identifier |
| Alternate key | a candidate key not chosen as primary (enforce with UNIQUE) |
| Composite key | a key made of two or more columns |
| Foreign key | a column referencing another table's key |
| Surrogate key | an artificial key (auto-increment, UUID) |
| Natural key | a key with business meaning (email, ISBN) |
Example
In Employees(EmployeeID, Email, PAN, Name): EmployeeID, Email and PAN are each candidate keys. EmployeeID is chosen as primary key (surrogate); Email and PAN are alternate keys with UNIQUE constraints; (EmployeeID, Name) is a super key but not a candidate key.