Is there a performance gain or best practice when it comes to using unique, numeric ID fields in a database table compared to using character-based ones?
For instance, if I had two tables:
athlete
id … 17, name … Rickey Henderson, teamid … 28
team
teamid … 28, teamname … Oakland
The athlete table, with thousands of players, would be easier to read if the teamid was, say, ‘OAK’ or ‘SD’ instead of ’28’ or ’31’. Let’s take for granted the teamid values would remain unique and consistent in character form.
I know you CAN use characters, but is it a bad idea for indexing, filtering, etc for any reason?
Please ignore the normalization argument as these tables are more complicated than the example.
I’d stay away from using text as your key – what happens in the future when you want to change the team ID for some team? You’d have to cascade that key change all through your data, when it’s the exact thing a primary key can avoid. Also, though I don’t have any emperical evidence, I’d think the INT key would be significantly faster than the text one.
Perhaps you can create views for your data that make it easier to consume, while still using a numeric primary key.