ENUM is a sort of enumeration. which means each column of the table has one of the possible values. It is a String Object. It uses a numeric index to represent string values.
Following are advantages of ENUM:-
- Compact Data Type
- Readable query
- It can accept integer, float, decimal, and string data types.
CREATE TABLE table_name (
Column2 ENUM (‘value_1′,’value_2′,’value_3’),
Above we use only three ENUM values but we can increase it more as per our need.
MySQL supports ENUM data type NULL, NOT NULL, DEFAULT.
CREATE TABLE employee(
ID INT PRIMARY_KEY AUTO_INCREMENT,
SEX ENUM(M, F)
following are the limitation of ENUM:-
- We cannot any variable for ENUM
- we cannot use an expression for ENUM
- After ALTER table only we can modify the ENUM value
- It is good practice to not use a numeric value for ENUM
- It is complex to get complete information of ENUM
- We cannot add additional value to the ENUM list.
Note:- MySQL sorts ENUM values based on their index numbers.