views:

292

answers:

5

Possible Duplicates:
Should I store Enum ID/values in the db or a C# enumeration?
Persisting Enums in database tables

Quick and easy question which will probably be fodder for discussion:

Let's say my application has an enum with 2-3 values which are basically never going to change.

Do you think those should be represented in the database in their own table and then referenced from other tables via foreign key relationships? Or should they be stored in the appropriate tables as simple integer fields containing the value of the enum?

Please explain your answer, also with respect to advocates of adherance to full third normal form design.

+1  A: 

Simple integer fields (no additional table) would do the work. It keeps everything simple.

Cătălin Pitiș
+1  A: 

Store them as simple integer fields, but also have a table for the enum with the integer and description. This can be joined or referred to as necessary.

Matt Howells
+1  A: 

What I do is store the enum integer value in the appropriate table column but also have a table in the database that represents the enumeration (with matching ids that match the enumeration values). Yes, it means you need to keep both the enum and the enum table up to date but like you said they are rarely going to change so it is not a big deal. The benefit is that you can use real names in your code with the enum and then also get the name of that enum value when querying the database.

Jeff Widmer
A: 

If this issue happens only once, you should use integer fields (KISS strategy), but if you have a lot of enumerated values, you could have a table with a tree structure for storing them.

Jonathan
A: 

I'd store them as simple integer fields containing the value of the enum in the appropriate tables. You could for reference, have a lookup table with each enum value listed along with it's corresponding description. My reason for this opinion, is that you don't want to introduce an extra unneccessary join, which you'd have to do if you didn't store the enum value in the table itself.

AdaTheDev