What is MySQL ENUM data type? What are the advantages to use ENUM data type?

MySQLMySQLi Database

The ENUM data type, different from standard data types, is an enumerated list of 1 to 65,535 strings indicating the allowed values for the field. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL).

For example, if you wanted your field to contain "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field.

Potentially followings are some advantages of ENUM data types −

  • Compact data storage can be observed in the situations where a column has a limited set of possible values.
  • The specified strings as input values are mechanically encoded as numbers.
  • The numbers are translated back to the corresponding strings in query result
  • By using ENUMs, we have readable queries and output.
raja
Published on 20-Feb-2018 05:50:25
Advertisements