by jackfoxy · 3y ago · 0 comments
Try to find a sample SQL database, for any vendor, that does not employ artificial table primary keys. This was a requirement in the 1980s so that your queries would execute before the heat death of the universe, but that has not been the case for decades. Microsoft is particularly guilty of this. Artificial keys are an anti-pattern. (And, btw, there's a dearth of literature on why artificial keys are an anti-pattern.)
Here's the only sample database I know of that consistently uses natural keys across all tables, created by a SQL educator who knows his stuff.
An artificial key is a column of made-up data added to the rest of the column. It has no use other than to provide uniqueness. In most cases there is already a unique candidate key in your data.
Why, in specific, are artificial keys an anti-pattern?
Seems like they preemptively solve problems. For example, using an SSN as a "natural" primary key is both a potential security nightmare and a data normalization nightmare if someone shows up with two or more SSNs, which does happen. (Yes. Yes. My great uncle had at least two SSNs. You won't convince me it can't happen.) Similarly for other "natural" data which isn't bound to obey the properties DBAs need for primary keys.