Hacker News new | ask | show | jobs
by wwweston 1845 days ago
It does seem that a "natural key" is frequently just a really foreign key in a database you and your org don't manage.
1 comments

That's a good observation. The only meaningful distinction between a natural key and a surrogate key is whether the number ever escapes the original system.

For instance, a driver's license number is printed on the card itself, so a human sees it. Therefore, it's a natural key, just like a name.

When you decide that whatever natural keys already exist aren't good enough for your organization, and you make a new key, it's not good to think of that as a surrogate key. The number will make it out somehow (as a "record locator" in a customer support call or something), and eventually become a natural key.

It's best to just plan for any new key to be a natural key, which means using best practices for natural keys. That means it should be something reasonable to print, read, say, and hear; and it should also follow a pattern so it can be distinguished from other special numbers.

Auto-increment is a shortcut, but usually not great in the long term unless it's something that will be well-contained inside the database as an implementation detail (e.g. a join key designed to refer to rarely-accessed fields of a wide table).