Mega Code Archive

 
Categories / MySQL Tutorial / Data Types
 

ENUM Type

The ENUM type is an enumerated list. A column can only store one of the values that are declared in the given list. An ENUM is a string object with a value chosen from a list of values that are enumerated at table creation time. An enumeration value must be a quoted string literal. mysql> mysql> CREATE TABLE Test(     ->     NY ENUM('Y','N') DEFAULT 'N',     ->     Size ENUM('S','M','L','XL','XXL'),     ->     Color ENUM('Black','Red','White')     -> ); Query OK, 0 rows affected (0.02 sec) mysql> mysql> Insert into Test (NY, Size, Color) values ('Y','S','Black'); Query OK, 1 row affected (0.02 sec) mysql> mysql> select * from Test; +------+------+-------+ | NY   | Size | Color | +------+------+-------+ | Y    | S    | Black | +------+------+-------+ 1 row in set (0.00 sec) mysql> mysql> drop table Test; Query OK, 0 rows affected (0.00 sec) mysql> mysql> You may have up to 65,535 items in your enumerated list. An ENUM type must either contain a value from the list or NULL. If you try to insert a value that is not in the list, a blank value will inserted.