SyntaxStudy
Sign Up
MySQL Surrogate vs Natural Keys
MySQL Intermediate 4 min read

Surrogate vs Natural Keys

Surrogate vs Natural Keys

Surrogate keys (auto-increment ID) are system-generated and stable. Natural keys (email, SSN) have real-world meaning but can change and may be long.

Example
-- Natural key: email as PK
CREATE TABLE users (email VARCHAR(255) PRIMARY KEY, name VARCHAR(100));
-- Problem: if email changes, all FK references break

-- Surrogate key: stable ID
CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) UNIQUE,
  name VARCHAR(100)
);
Pro Tip

Use surrogate keys as PK, but keep natural keys as UNIQUE constraints.