ENUM Type : ENUM « Data Types « MySQL Tutorial






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.









10.10.ENUM
10.10.1.ENUM Type
10.10.2.Possible value for a ENUM column
10.10.3.ENUM with default value
10.10.4.Use ENUM type column
10.10.5.Inserting data to ENUM type column
10.10.6.Use numeric operation in ENUM type column
10.10.7.If you retrieve an ENUM value in a numeric context, the column value's index is returned