Natural or Made-Up Keys? Two Sides for Beginners

Every table needs a primary key: a column, or set of columns, that uniquely identifies each row. Should that key be something real, like an email address, or a made-up number? Database designers have debated this for a long time. Here are both sides.

Two kinds of key

A natural key is a value that already exists in the real world and is unique, such as a country's two-letter code or a book's ISBN.

A surrogate key is a value the database makes up, usually a number that counts up (1, 2, 3...) or a long random identifier. It has no meaning outside the database.

-- surrogate key
CREATE TABLE members (
  id    INTEGER PRIMARY KEY,
  email TEXT NOT NULL UNIQUE,
  name  TEXT
);

-- natural key
CREATE TABLE countries (
  code TEXT PRIMARY KEY,   -- e.g. 'FR', 'JP'
  name TEXT NOT NULL
);

The case for natural keys

  1. They mean something. Seeing 'FR' in another table is clearer than seeing 17.
  2. No extra column. The unique value is already there.
  3. They prevent duplicates naturally. You cannot accidentally add France twice.

The case for surrogate keys

  1. Real-world values change. People change email addresses; product codes get reused. If a key changes, every table that refers to it must change too.
  2. Real-world values are not always unique. Two people can share a name; some may not have an email at all.
  3. They are small and simple. A whole number is compact and quick to compare.
  4. They keep private data out of other tables. Using an email as a key means copying it into every table that refers to members.

Comparing them

QuestionNatural keySurrogate key
Meaningful to read?YesNo
Can it change?SometimesNever needs to
Guaranteed unique?Only if the real world guarantees itYes, the database makes sure
SizeVariesUsually small
Stops duplicate real-world entries?YesOnly if you also add a UNIQUE rule

A practical rule for first projects

Use a surrogate key (id INTEGER PRIMARY KEY) for most tables, and add a UNIQUE constraint on any real-world value that must not repeat, such as an email. You get stable keys and protection against duplicates.

Use a natural key for small, stable lookup tables where the value truly never changes and is officially defined, such as country codes from the ISO 3166 standard.

A common beginner mistake

Using a surrogate key but forgetting the UNIQUE rule. Then the same member can be added twice with different ids, and nothing stops it. The key is unique, but the person is duplicated.

Where opinions still differ

Some designers prefer natural keys wherever a good one exists, arguing that surrogate keys hide duplicate data. Others use surrogate keys everywhere for consistency. Both approaches can work well when applied carefully.

To practise choosing, try our practice session on picking a good primary key.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.

This is a static page of sample discussion topics. There is no live forum, membership or user community on this site.