Skip to content
>devspeak
← glossary
level 4Databases

Primary key

also: primary keys, pk

The column that gives each row its own unique ID, so the database can always tell one row from another. It's usually called "id".

a bit more technical

A column, or combination of columns, whose value uniquely identifies each row in a table. It must be unique and never null. Common choices are auto-incrementing integers or UUIDs. Other tables point to it using foreign keys.

picture it

A passport number. Two people can share a name and birthday, but never a passport number. Anyone who needs to identify you exactly uses that number.

why it matters

Many "the wrong customer got updated" bugs come down to which identifier was used. Knowing the primary key is a row's real identity helps you ask agents to target data precisely.

what your agent might say
agent
I'll look up the order by its primary key rather than the customer's email, since several customers share a family email address.
how you might use it
you → your agent
When you fix that customer's account, target it by its primary key, not by name, and confirm the id with me first.
common mistake

Thinking something like an email address makes a good primary key. Emails change and can be shared. A primary key should be stable and never reused.

builds on