Results 1 to 7 of 7
  1. #1
    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?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    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:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    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"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    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

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    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
    Home | Blog

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    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:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •