ENUM Type : ENUM : Data Types MySQL TUTORIALS


MySQL TUTORIALS » Data Types » ENUM »

 

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, rows affected (0.02 sec)

mysql>
mysql> Insert into Test (NY, Size, Colorvalues ('Y','S','Black');
Query OK, row affected (0.02 sec)

mysql>
mysql> select from Test;
+------+------+-------+
| NY   | Size | Color |
+------+------+-------+
| Y    | S    | Black |
+------+------+-------+
row in set (0.00 sec)

mysql>
mysql> drop table Test;
Query OK, 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.




Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Data Types
» ENUM