juniorMySQL
Purpose of the Primary Key
Updated May 4, 2026
Short answer
A unique identifier for each row that cannot be NULL.
Deep explanation
In InnoDB, the PK is the clustered index, meaning data is physically sorted by it on disk. Only one PK is allowed per table.
Real-world example
An AUTO_INCREMENT 'id' column used as the PK for a customers table.
Common mistakes
- Choosing a column that might change, like an email, as a Primary Key.
Follow-up questions
- Can a PK be composite?