If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > How To Store Enum Values?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-08, 02:44
CrazyTn CrazyTn is offline
Registered User
 
Join Date: May 2007
Posts: 24
How To Store Enum Values?

For example a customer has three payment types.
Cash, Credit, or Check

Would it be best to store these three option in an Enum or a String[]?

If it is better to use an enum, would you store the string value or the int value in the database?
Reply With Quote
  #2 (permalink)  
Old 04-30-08, 03:47
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Wrong way round IMHO. Decide how you are storing the data (surrogate or natural key) and then build the app to suit that. Personally, I would use natural keys and cache this (likely unchanging) data at the client. Not bother with enums at all.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 04-30-08, 08:11
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
There is no such thing as a lookup table. Treat this data no different than any other data in your database. If your standard is to use natural keys, then use natural keys. If your standard is to use surrogate keys, then create a surrogate key for these values.
And if you not referring to surrogate keys, but actually mean true .net "enums", well the whole practice of dynamically creating surrogate database keys in the applicaiton layer is so lame that I don't really want to get into it.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #4 (permalink)  
Old 04-30-08, 08:17
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
what happens if there are additional types eg debit card
in my books it has to be a table, ENUMS are fine for the very limited occasion where every possible value in perpetuity is known at design time, but even then they can still fail if you say move the db to another language. the often quoted example are Male / Female using M or F as the Key. but that can fall down in these modern times with a move to non English, or the addition of other categories eg Trannies

I'd go along with the idea of not alwasy using surrogate values for the key, it can make the data a heck of a lot easier to read.

eg
£: Cash
A: Account
C: Credit Card
D: Debit Card
.......
rather than
1: Cash
2: Account
3: Credit Card
4: Debit Card
Reply With Quote
  #5 (permalink)  
Old 04-30-08, 08:26
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Quote:
Originally Posted by healdem
eg Trannies
That's so unpolitically correct that I love it!

And remember, if you are using a surrogate key, you should nigh-on-always declare a unique constraint appropriately too!
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 04-30-08, 09:10
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by healdem
eg Trannies
Unpolitically correct and inaccurate. That is not another gender in any book. Do you mean transgender as opposed to transvestite?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #7 (permalink)  
Old 04-30-08, 13:12
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
Quote:
Originally Posted by pootle flump
Unpolitically correct and inaccurate. That is not another gender in any book. Do you mean transgender as opposed to transvestite?
I'll bow to your knowledge on the subject
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On