what datatype to use for a field that can contain a value from pre-defined values in a database table?
I have one field named type
in a datab开发者_开发问答ase table. I want this field to contain a value from a list of pre-defined values. If I use set
as the datatype of this field, then it can contain more than one values from the list.
What datatype to use, so that It can contain only one value from the list of values (pre-defined)?
For mySQL, you want ENUM.
An ENUM is a string object with a value chosen from a list of allowed values that are enumerated explicitly in the column specification at table creation time.
MS SQL does not have a ENUM type as far as I know. (Correct me if I'm wrong.) You would usually use integer values, and resolve them in the application. To limit the range of possible values, the CHECK constraint can be used.
You need to use enum
data type for that.
See More: http://dev.mysql.com/doc/refman/5.0/en/enum.html
精彩评论