The context of databases and relational database management systems (RDBMS), a “key” in a relation refers to a set of one or more attributes (columns) that can uniquely identify a tuple (row) in that relation. Keys play a crucial role in maintaining the integrity and structure of a relational database.
Difference between Super key, Candidate key and Primary key:
Feature | Super Key | Candidate Key | Primary Key |
---|---|---|---|
Definition | An attribute or set of attributes that uniquely identifies all attributes in a relation. | A minimal set of super key. | A minimal set of attributes that uniquely identifies rows in a relation. |
All are Super Keys | Yes | Yes | No |
Null Values | Can be null | Can be null | Cannot be null |
Number of Keys | Any number of super keys can exist. | Number of candidate keys is less than super keys. | Number of primary keys is less than candidate keys. |
Example (from Fig. 1.23.1) | (Registration), (Vehicle_id), (Registration, Vehicle_id), (Registration, Vehicle_id, Make), etc. | (Registration, Vehicle_id) | (Registration) |