ENUM
Stores one value of a predefined list of possible strings. When you
create an ENUM
column, you provide a list of all
possible values. Inserts and updates are allowed to set the column to
values only from that list. Any attempt to insert a value that is not
part of the enumeration will cause an empty string to be stored
instead.
You may reference the list of possible values by index where the index of the first possible value is 0. For example:
SELECT COLID FROM TBL WHERE COLENUM = 0;
Assuming COLID
is a primary key column and
COLENUM
is the column of type
ENUM
, this SQL will retrieve the primary keys of
all rows in which the COLENUM
value equals the
first value of that list. Similarly, sorting on
ENUM
columns happens according to index, not
string value.
The maximum number of elements allowed for an ENUM
column is 65,535.