views:

24

answers:

2

I have one field named type in a database 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)?

+1  A: 

You need to use enum data type for that.

See More: http://dev.mysql.com/doc/refman/5.0/en/enum.html

Sarfraz
+1  A: 

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.

Pekka
+1 ......... thanks :)
Yatendra Goel
could you please look at the question at http://stackoverflow.com/questions/2301773/database-table-design-problem
Yatendra Goel