Primary Key
PronunciationPRY-meh-ree KEE
Definition
A primary key is a column or a set of columns in a database table that uniquely identifies each row. It ensures that no two rows have the same value in this field and that the value is never null.
Where you hear it
You hear this when designing database schemas, writing SQL queries, or configuring an ORM.
Examples
The
user_idcolumn is set as the primary key for the users table.Every table in the database must have a primary key to ensure data integrity.
The order ID is the primary key, so two orders can never share it.
Common mistake
Assuming that a primary key can contain duplicate values or nulls, which would break the fundamental rule of database uniqueness.
Don't confuse with
Primary key uniquely identifies each row and cannot be null, while a foreign key links to a primary key in another table and can sometimes accept null values.
Say it at work
- In a meeting or chat
Can we use a composite primary key for this mapping table, or should we stick to an auto-incrementing ID?
- In an email or ticket
Please ensure that every table created in this migration has a proper primary key defined.