DavidSzczesniak
1/22/2018 - 5:22 PM

ENUM() string type

ENUM('value1'[, 'value2'[, ...]])
-- Enumeration (or list) of string values.
-- Compact way of storing values from a list of predefined values (value1, value2 etc. above).

\!h Example - the name can be any one of the predefined values Apple, Orange, Pear(+ NULL and the empty string).
CREATE TABLE fruits_enum (fruit_name ENUM('Apple', 'Orange', 'Pear')); -- creates enum table

INSERT INTO fruits_enum VALUES ('Apple'); -- this works because Apple is predefined

INSERT INTO fruits_enum VALUES ('Banana'); -- won't work, not predefined - empty string is stored instead

INSERT INTO fruits_enum VALUES ('Apple', 'Pear'); -- won't work, can't store multiple values at once - empty string stored again

\!h Give the empty string a default value:
CREATE TABLE fruits_enum (fruit_name ENUM('Apple', 'Orange', 'Pear') DEFAULT 'Pear');