Re:The problem with invariants is that they change over time
by CodesInChaos on Tuesday April 23, 2024 @12:21PM
(#40133739)
I almost always use surrogate keys as primary keys (or a tuple of them, for join-tables). Natural keys are rarely as immutable and unique as we'd like.
Even ISO country codes can be problematic, for example we currently use XK for Kosovo, but it might get an official code at some point.
Re:The problem with invariants is that they change over time
by bruce511 on Tuesday April 23, 2024 @03:17PM
(#40136011)
It's less about literature, and more about experience.
Over the years just about every natural key I've seen ends up being either not-universal (-everyone- has a phone number right? Even that new-born baby?) Or not unique (phone numbers can be shared) or mutable (like people's names changing).
It's just so much easier to add a column and use a surrogate key. I prefer uuids because they are unique And immutable - properties I really appreciate in primary keys.
Every material about relational data I've seen either just explains them, says they can be either natural or artificial, and leaves at that, or says there's some disagreement over what is better.
The unanimity exists only within field experts that apply the stuff. The theoreticians all disagree.