A primary key is a column (or a set of columns) whose value uniquely identifies every row in a database table. If you know a row’s primary key, you know exactly which row you’re talking about — no ambiguity, no duplicates.
What the constraint actually enforces
In a relational database, declaring a primary key is a promise the database itself enforces. Two rules come with it:
- Uniqueness: no two rows can share the same primary key value.
- Not null: the primary key column can never be empty.
You declare it when you create the table:
CREATE TABLE customers (
id INT PRIMARY KEY,
email TEXT NOT NULL,
signed_up_at TIMESTAMP
);
Try to insert a second row with id = 42, and the database rejects the write. That’s the point: the constraint stops bad data from getting in, rather than leaving you to find duplicates months later in a report.
Natural keys vs. surrogate keys
A natural key is a column that’s already meaningful to the business and happens to be unique — an ISBN, a country code, a SKU. A surrogate key is a value invented purely to identify the row: an auto-incrementing integer, or a UUID.
Surrogate keys are the common default, because natural keys have a habit of changing. Email addresses get updated, product codes get restructured after an acquisition, and a “unique” phone number turns out to be shared by two people at the same company. When a key changes, every table that references it has to change too. A meaningless integer never has that problem.
Why analysts care
Primary keys are what make joins trustworthy. A foreign key in one table points at the primary key of another, and that pairing is how orders knows which customer placed it. If the key you’re joining on isn’t actually unique, the join silently multiplies rows — one order matches three customer records, your revenue total triples, and nothing in the query errors out.
Primary keys also make normalization possible. Splitting data into separate tables only works if each table has a stable identifier that other tables can reference.
Primary keys in Metabase
When Metabase syncs a database, it reads the declared primary key constraints and marks those columns with the Entity Key field type. That’s the tag that lets Metabase link related records together and offer drill-through into a single row’s detail view. If your warehouse tables don’t declare constraints — which is common in analytical databases — an admin can set the Entity Key field type by hand on the Data Model page.
Related terms
Further reading
Put it to work
- Stripe — Integration
- Revenue analytics — Overview
- Build a data pipeline — Integration