Primary keys, foreign keys and data modelling
How to choose identifiers and relationships so your model survives integrations and analytics.
Every row needs a stable identity
A primary key uniquely identifies a row for its lifetime. Prefer keys that do not change when a user edits their email. Surrogate keys (integers, UUIDs) plus a unique business key (email, SKU) is a common, boring, good pattern.
Foreign keys are documentation that the database can enforce
They prevent orphan lines and make joins honest. If you skip them for speed, you must enforce the same rule in application code — and you will forget.
Modelling for integrations
Publish the business key to other systems (single source of truth). Do not make a partner depend on your internal auto-increment if you can give them a UUID.
Related
Last verified: August 2026. Technology and pricing change — always confirm current details with the vendor.