|
|
|
|
|
by gregjor
1328 days ago
|
|
I think the author confuses primary keys with surrogate keys. The article compares various surrogate keys in technical terms, but doesn't address "Choosing the best database primary key." A natural key usually makes the best primary in terms of database design, usability, and longevity. If you can't identify a natural key that indicates failure to normalize or even the wrong model of the data. Optimizing for storage, "performance," or "exposing the primary key to the world" (why?) may matter in some cases, but at the expense of not having an actual relational model, just a pile of data wedged into a relational database management system. |
|
If you can't identify a natural key that indicates failure to normalize or even the wrong model of the data.
I'm not sure about this point. As a matter of fact a lot of entities in the real world do not have a natural key, or if they have it, it could be subject to changes. How do you identify a user or an anonymous post on a forum?
Maybe for an user you could just use the email. Then, what if the user want to change their email? Or what if one day you want to allow users to sign-up with just their social login?
Surrogate keys are always a good level of indirection to keep a consistent identity, and especially useful as foreign key and hence also as a primary key. Of course with some exceptions (eg. intermediate tables, where the PK is spanning across multiple columns)
But I'm curious to know also other scenarios since my view is skewed by the business domain I work in.