How can I use enum and set data types in MySQL ?

Discussion in 'MySQL' started by karumi, Mar 5, 2010.

  1. #1
    Hi, I know that I am not good at learning something new.
    Yesterday I studied my second day about MySQL data types and I realize that I do not know how to use "Enum" and "Set" data types. Please help me :(
     
    karumi, Mar 5, 2010 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    enum aka (ENUMERATION) it's for seting options like 'yes','no' and that's all you can insert into that field
    set - similar to enum but less restrictive
     
    crivion, Mar 6, 2010 IP
  3. karumi

    karumi Peon

    Messages:
    142
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you show me some examples of using them ?
     
    karumi, Mar 7, 2010 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    If you had a form that is auto-filled from a database. The possible values could be Yes, No, Maybe. These could be stored in an ENUM type column. This would save space, increase query speed, and would restrict the values that could be entered into the column. You could also use it for numerical keys like: 0,1,2,3. Same thing, the values that can be entered would be restricted. Alternately you could use a tinyint, but a user could enter 6, 9 4, or something that has no meaning to your application. ENUM prevents bad data while increasing performance in many cases.

    You wouldn't want to use enum on large sets, as then the overhead for storing the enum data outweighs the benefits, but for small sets of values, it's a great way to restrict user input.
     
    jestep, Mar 8, 2010 IP