🗄️ Database Design / Normalization
Beginner
What is a surrogate key vs natural key?
Answer
A natural key is a column with real-world meaning that naturally identifies a row (e.g., email address, SSN, ISBN). It can be meaningful but may change over time (people change emails) and can be long (inefficient for joins). A surrogate key is an artificially generated identifier with no business meaning — typically an auto-incrementing integer (SERIAL/AUTO_INCREMENT) or UUID. Surrogate keys are immutable, compact (4–16 bytes), and uniform across tables. Best practice: use surrogate keys as primary keys for most tables, and add unique constraints on natural keys where needed for business uniqueness rules.