enum fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    enum fields

    hii,
    I have a enum field in database ,which i break up using php and make it a dropdown list in the form . i have a requirement now such that from the list the person must be able to select 2 items together which is also done.but can i store 2 values in a db column which is an enum field?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    but can i store 2 values in a db column which is an enum field?
    Not with an ENUM field, no. They only accept single values in the ENUM list.
    In any case, you shouldn't even attempt to do that. It violates basic RDMS design principles.

    The first rule of relational database design (1NF, the 1'st Normal Form):
    - Never put more than a single value into any one field.

    When multiple values of the same data-type need to be linked to a single row (e.g. multiple phone numbers for a single person), the standard method is to move that column out of the main table and put it into a separate table, which is then linked to the main table using a Foreign Key.

    For example:
    Code:
    +---------+     +--------------------+
    | person  |     | phone_number       |
    +---------+     +--------------------+
    | id (PK) |<---<| person_id (PK, FK) |
    | name    |     | number (PK)        |
    | etc...  |     +--------------------+
    +---------+
    There a single person can be linked to multiple numbers, but only once to a each number. (The 'person_id' and 'number' would be a joint key, preventing duplicate pairs.)

    The same principle holds for ENUM fields. If one row in a table needs to be linked to multiple values of the ENUM column, move it into it's own table and set up a Foreign Key link.

    Comment

    Working...