Interview Q&A / SQL & DBMS

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between a surrogate key and a natural key?

SHORT ANSWER

A natural key is a real-world attribute that is unique, like email or Aadhaar number. A surrogate key is a meaningless generated value, like an auto-increment id. Surrogate keys stay stable when business data changes.

Explain it simply

A natural key is a name written on a school bench: meaningful but it can change if the student moves or corrects a spelling. A surrogate key is the number stamped on the bench by the school. It means nothing, but it never changes.

Example

sql
-- natural key
CREATE TABLE users_a (
  email VARCHAR(100) PRIMARY KEY,
  name  VARCHAR(50)
);

-- surrogate key
CREATE TABLE users_b (
  id    BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email VARCHAR(100) NOT NULL UNIQUE,
  name  VARCHAR(50)
);

If a user changes email in users_a, every foreign key pointing to it must change too. In users_b, only one column changes.

NaturalSurrogate
MeaningReal-worldNone
StabilityMay changeNever changes
SizeOften long textSmall integer
Needs UNIQUE on business dataNoYes

Use a natural key when it is truly stable and short, such as a country code. Otherwise a surrogate key with a UNIQUE constraint on the natural one is the common choice.

What to say in the interview

"A natural key comes from the data, a surrogate is generated. Surrogates are small and stable, but I still keep a UNIQUE constraint on the natural identifier so duplicates are not allowed."

Common mistakes

  • Using a surrogate key and dropping the unique constraint on email.

#dbms#keys#surrogate-key#natural-key

Related questions

Practise more SQL & DBMS questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open SQL & DBMS quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.