4 ms·
I can agree with everything in the article except this one. >Has anyone had a problem due to surrogate keys? There's one problem with surrogate keys: they are
by ComodoHacker 6y ago
I can agree with everything in the article except this one.
>Has anyone had a problem due to surrogate keys?
There's one problem with surrogate keys: they are not convenient to users (too long and not meaningful).
There are two problems with natural primary keys, and you are guaranteed to hit one of them at some point.
1. It turns out your key isn't actually unique. To resolve the collision you have to replace natural key with a surrogate for one of conflicting entities. Which is not always possible without risk of another collision.
2. It turns out your key isn't persistent. You have to change it for some entities, but you can't because of so many FKs.
- Scarbutt 6y agoThere's one problem with surrogate keys: they are not convenient to users (too long and not meaningful). You shouldn't expose those keys to users though.
- brantam 6y agoThe article mentions auto-incrementing keys, not surrogates. Not the same thing at all. Not all incrementing keys are surrogates and not all surrogates are incrementing keys. Also, your problem number 1 is a problem whether the natural key in question is the "primary" one or not. Certainly if you choose the wrong natural key then you'll have to fix that - that's why you should take care to make a wise choice of natural key regardless of whether you are also using a surrogate.