Junior — Middle
What are the main criteria to consider when choosing and defining a primary key in a database table?
sobes.tech AI
Answer from AI
When choosing a primary key in a database table, the following criteria should be considered:
- Uniqueness: The key value must uniquely identify each record.
- Immutability: The primary key value should not change over time.
- Minimal size: The key should be compact to optimize indexes and performance.
- Simplicity: It is better to use a simple data type (e.g., numeric or UUID).
- No NULLs: The primary key cannot contain NULL.
For example, an auto-incrementing numeric field or UUID is often used as a primary key.