i'm creating database various tables. let's take user table, example. has fields such marital status , system role. each of fields has predefined options. make sense create 2 new tables each of fields, when user added system, choices can made available selection e.g. single, married, divorced? seems bit of overkill in terms of 1 query. best way or have other options?
you can use enum datatype in mysql better take care of scenario. storing such options in seperate table bad idea until have lot of them..
mysql> desc classes; +-------+-----------------------+------+-----+---------+-------+ | field | type | null | key | default | | +-------+-----------------------+------+-----+---------+-------+ | id | int(11) | no | pri | null | | | dept | char(4) | no | | null | | | level | enum('upper','lower') | no | | null | | +-------+-----------------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> select * classes; +----+------+-------+ | id | dept | level | +----+------+-------+ | 10 | math | | +----+------+-------+ 1 row in set (0.00 sec) mysql> insert classes values (11, 'eng', 'upper') -> ; query ok, 1 row affected (0.00 sec) mysql> select * classes; +----+------+-------+ | id | dept | level | +----+------+-------+ | 10 | math | | | 11 | eng | upper | +----+------+-------+ 2 rows in set (0.00 sec)
Comments
Post a Comment