r/DatabaseHelp • u/Mondoscuro • Jul 12 '18
Normalization
Example: there is a table named "car" that contains cars data and a "color" field that contains the color of the car.
Would be enough to use an "enum" data type if I knew the colors would never change?
Or could I do a table "colors" that has only one field primary key, that directly contain color names like "red", "blue", etc
Or for normalization purposes should I do a table like this:
1 red
2 blue
3 black
4 white
And link color to cars using ID instead of using the names themselves as IDs?
I hope I was clear enough
2
Upvotes
View all comments
Show parent comment
2
u/iPlayKeys Jul 24 '18
That's actually the basics of normalization. At some point, it's likely you will have another table that references color, or you might have additional attributes of a color, or (and this is the most likely), you'll want to change the name of a color. If you're using a lookup table, you change it in one place, because you've used a placeholder (the ColorID) field in your other table. If you actually store "RED" in the table, you'll have to update all rows that currently say "RED" for color.