A primary key is a field, or set of fields, that uniquely identifies each row in a database table, so no two records can share it.
Data · Reviewed by Ray Rasouli
Ask about primary key
Plain answers, with your setup in mind.
Ask anything about primary key. For example, how it works in your current tools.
A scripted guide for now. It does not store what you type.
Every customer, order or item in a database needs a reliable way to be told apart from the rest. Names are not good enough, since two customers can share a name and names change. A primary key is usually a number or code that never repeats and never changes.
A parts distributor stores customers in its ERP with a customer ID. When it connects its online store, matching on that ID, rather than on company name or email, keeps orders linked to the right account.
Primary keys also let tables link to each other. An order row stores the customer ID, which points back to exactly one customer.
In practice
Meaningful values are used as keys.
Using an email or phone number as the key causes trouble when the customer changes it.
Systems use different keys for the same thing.
If the ERP and CRM each have their own customer ID with no mapping, integrations match on names and create duplicates.
Keys get reused.
Reassigning an old item code to a new product mixes the history of two different things.
A primary key identifies a row in its own table. A foreign key is a field in another table that stores that value to link back to it, like a customer ID on an order.
Yes. That is called a composite key, for example an order number plus a line number to identify each order line.
A 30-minute discovery call with Ray, then a clear list of what to fix first. No obligation.
With Ray Rasouli. No obligation.