Where Did I Leave My (Primary) Keys???
summary
Builds two small SQL Server databases—one using surrogate integer IDs with a clustered identity, the other using natural keys—and runs benchmarks and execution plans. Inserts run about 40s vs 41s so insert cost is similar; singleton lookups are similar too, but range LIKE queries cause the ID design to scan while naturals get an index range seek. A grouped top-10 countries query eliminates multiple joins and becomes orders of magnitude faster; updates on natural keys trigger many cascaded writes. Code, scripts and materials are provided.
AI-written summary · about
chapters (14)
- 0:00Introduction to key selection
- 3:09Types of database keys explained
- 7:01Surrogate vs natural keys debate
- 10:12Common claims about artificial keys
- 18:01Pros of natural keys
- 23:19Demo setup: artificial keys schema
- 25:31Demo setup: natural keys schema
- 27:59Query performance: singleton lookups
- 30:10Query performance: range scans
- 32:21Query performance: top countries report
- 34:50Query performance: joins reduction
- 37:47Update performance comparison
- 40:20Key selection guidelines
- 42:30Resources and closing
