You'll regret using natural keys
blog.ploeh.dk
You'll regret using natural keys
1–10 of 568 posts
Re: You'll regret using natural keys
#2Even if just for documenting issues it makes life easier. “Table whatever id 12345 is the record in question.”
I’ve just seen data / relationships change too much too often in new and interesting ways to believe in using a natural key.
Re: You'll regret using natural keys
#3Re: You'll regret using natural keys
#4[deleted]
Re: You'll regret using natural keys
#5Notice that even if you believe that you should 'never use natural keys', that is NOT the same thing as 'always add a generated synthetic key to every table as the primary key'. You should NOT always add a generated key to every table, even if you use a trash ORM that really wants you to do this.
Re: You'll regret using natural keys
#6Sometimes you will regret it, other times you won't. Notice that even if you believe that you should 'never use natural keys', that is NOT the same thing as 'always add a generated synthetic key to every table as the primary key'. You should NOT always add a generated key to every table, even if you use a trash ORM that really wants you to do this.
Re: You'll regret using natural keys
#7 model: DiscordMessage
key = discord_message_id
key = discord_user_id
key = discord_channel_id
key = message_type
model: UserData
key = discord_user_id
key = field_name
model: GuildFeature
key = discord_guild_id
key = well_known_feature_name
model: DiscordEvent
key = discord_event_id
key = discord_guild_id
This is how I was always taught to use them so I'm kinda confused what the author is getting at. If the thing you're using as a key can change and that doesn't define the row then you don't have a key. If you're at a conference where everyone has a badge number then that's a great natural key when scanning people into your workshop. If you're at Disney and everyone has a magicband with ids then you can use that as a natural key all over the place when to you that's a visitor.Re: You'll regret using natural keys
#8Natural keys are great when they're someone else's synthetic keys. My Discord bots make liberal use of this. model: DiscordMessage key = discord_message_id key = discord_user_id key = discord_channel_id key = message_type model: UserData key = discord_user_id key = field_name model: GuildFeature key = discord_guild_id key = well_known_feature_name model: DiscordEvent key = discord_event_id key = discord_guild_id This…
(Disclaimer: not a Discord bot programmer.)
Suppose discord_user_id is an identifier like @Spivak#2024 that uniquely identifies the user. When Discord forces all users to change to unique ID's and eliminates the disambiguating numbers (or allows users to change them), then where does that leave you?
(For the unfamiliar: something like this happened. Not sure if those are really the "discord user id" used in bot service though, but suppose that they are for the sake of the argument.)