r/DatabaseHelp • • 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

3 comments sorted by

View all comments

Show parent comment

1

u/Mondoscuro Jul 13 '18

Yeah it's just that to me, having a lookup table with two generally unique fields like "id" and "label" of whatever (not just color) feels a step back from normalization, instead of a step forward, but I can't find a proper guideline on this.

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.