Loading

ENUM MySQL Data Type

ENUM MySQL Data Type 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.

The following are the advantages of ENUM:-

  • Compact Data Type
  • Readable query
  • It can accept integer, float, decimal, and string data types.

Syntax:-

CREATE TABLE table_name (

Column1,

Column2 ENUM (‘value_1′,’value_2′,’value_3’),

Column3…

);

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.

Example:-

CREATE TABLE employee(

ID INT PRIMARY_KEY AUTO_INCREMENT,

name VARCHAR(255),

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 on ENUM
  • We cannot add additional value to the ENUM list.

Note:-  MySQL sorts ENUM values based on their index numbers.

Read Also:-

BIT MySQL Data Type
TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT MySQL Data Type
BOOLEAN, FLOAT, DOUBLE, DECIMAL MYSQL Data Type
CHAR and VARCHAR MySQL Data Type
MYSQLSET Data Type
MySQL BINARY and VARBINARY Data Type

For more detail about Data Type, Please visit Mysql Manual

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w
Verified by ExactMetrics