Account
Categories

ENUM Data Type


ENUM data type refers to storing a predefined set of values.
When you create a table in MySQL, you define the ENUM data type with specific values so that only one of the predefined values can be inserted into that column.

Syntax:

column_name ENUM('value1', 'value2', ...)

Example:

Suppose you want to create a table for storing the status of orders, where the status can only be 'Pending', 'Shipped', or 'Delivered'. Then you will use the ENUM data type.

Query:

CREATE TABLE orders (
    order_id INT,
    order_status ENUM('Pending', 'Shipped', 'Delivered')
);
  

Output:

order_id | order_status
------------------------
101      | Pending
102      | Shipped
103      | Delivered
    

Explanation:

  • The column order_status can only have one of the three predefined values.
  • If you try to insert a value outside this list, MySQL will not allow it.