What is a natural key, and how does it compare with a surrogate key for a primary key?
Answer
A natural key is a primary key made from data that already exists in the business domain and uniquely identifies the entity, such as an ISBN for a book, an IFSC code for a bank branch, or a GSTIN for a registered business. A surrogate key is an artificial identifier with no business meaning, such as an auto-increment integer or a UUID. Most production systems use a surrogate primary key and enforce the natural key with a separate UNIQUE constraint.
Candidate, natural and surrogate keys
Candidate key: any minimal set of columns that uniquely identifies a row. A table can have several.
Natural key: a candidate key taken from real-world data.
Surrogate key: a system-generated value added only to identify rows.
Advantages of natural keys
No extra column; the identifier already means something.
Uniqueness is enforced by the primary key itself, so duplicates of the real entity cannot sneak in.
Joins can sometimes be skipped because the child table already holds a meaningful value (for example country_code = 'IN').
Good fits: ISO country and currency codes, IFSC codes, airport codes, ISBN in a library system.
Why natural keys often go wrong
They change. Emails, phone numbers, usernames and even company names change. Updating a primary key means updating every foreign key that references it.
They are not as unique as assumed. Names collide, some books lack an ISBN, phone numbers get recycled by telecom operators.
They may be missing at creation time, such as a student who does not have a university roll number yet.
Privacy and compliance. Using Aadhaar or PAN as a key spreads sensitive identifiers into every child table, logs and URLs. Under India's Digital Personal Data Protection Act 2023 and Aadhaar rules, that is a liability.
Size. A long text key makes every index and foreign key bigger than an 8-byte integer.
Comparison
Aspect
Natural key
Surrogate key
Meaning
Business meaning
None
Stability
Can change
Never changes
Size
Often wide text
8-byte BIGINT or 16-byte UUID
Duplicate protection
Built in
Needs a separate UNIQUE constraint
Exposure risk
May leak sensitive data
Safe to expose (UUIDs especially)
Good examples
Currency code, IFSC
Users, orders, payments
The practical recommendation
Use a surrogate primary key (BIGINT GENERATED ALWAYS AS IDENTITY, or a time-ordered UUIDv7 if IDs are generated across services) and add a UNIQUE constraint on the natural key. You get stable joins plus protection against duplicate real-world entities. Keep natural primary keys for small, stable reference tables where the code itself is the identity.
Common mistakes
Using a surrogate key and forgetting the UNIQUE constraint on the natural key, which lets the same GSTIN be registered twice.
Choosing email as a primary key, then supporting "change my email".
Exposing sequential integer IDs in public URLs, which lets anyone enumerate records.
Natural key vs surrogate key. The common answer is both: surrogate primary key plus a unique natural key.
Natural key
Surrogate key
Example
IFSC code, ISBN, GSTIN
BIGINT identity or UUIDv7
Can it change?
Yes, sometimes
No
Prevents duplicate entities
Yes, by itself
Only with a UNIQUE constraint
Best for
Small stable reference tables
Core entities like users and orders
Code examples
Surrogate primary key plus unique natural key
CREATE TABLE merchants (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- surrogate
gstin CHAR(15) NOT NULL UNIQUE, -- natural key, enforced
legal_name TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Natural primary key is fine for a stable reference table
CREATE TABLE bank_branches (
ifsc CHAR(11) PRIMARY KEY,
bank_name TEXT NOT NULL,
city TEXT NOT NULL
);
Merchants get a stable internal id while GSTIN uniqueness is still guaranteed; branches use the IFSC code directly because it is the identity.
Key points
Natural key: real-world identifier like ISBN, IFSC or GSTIN. Surrogate key: generated with no meaning.
Natural keys can change, collide or be missing, which breaks foreign keys.
Avoid sensitive identifiers like Aadhaar or PAN as keys.
Best practice: surrogate primary key plus UNIQUE constraint on the natural key.