
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we create and use ENUM columns in MySQL?
For creating an ENUM column, the enumeration value must be a quoted string literals. We can create ENUM columns in MySQL with the help of the following syntax −
CREATE TABLE table_name( … Col ENUM(‘Value1’,’Value2’,’Value3’), … );
In the above syntax, we have three enumeration values. It can be more than three also.
Example:
Following is an example of creating a table with ENUM column −
mysql> Create table marks(id int Primary key NOT NULL, Name Varchar(255) NOT NULL, Result ENUM('Pass', 'Fail') NOT NULL); Query OK, 0 rows affected (0.18 sec)
The query above will create a table named marks with an ENUM field.
mysql> Insert into marks(id, name, result) values(101,'Aarav','Pass'); Query OK, 1 row affected (0.07 sec) mysql> Insert into marks(id, name, result) values(102,'Yashraj','Fail'); Query OK, 1 row affected (0.02 sec)
With the help of queries above we can insert the values in the table.
mysql> Select * from marks; +-----+---------+--------+ | id | Name | Result | +-----+---------+--------+ | 101 | Aarav | Pass | | 102 | Yashraj | Fail | +-----+---------+--------+ 2 rows in set (0.00 sec)
- Related Articles
- How can we create and use a MySQL trigger?
- How can we use two columns with MySQL WHERE clause?
- Can we create an enum with custom values in java?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we create MySQL views?
- How can we use prepared statements in MySQL?
- How can we use nested transactions in MySQL?
- How can we use MySQL SUM() function?
- How can we list all the columns of a MySQL view as we can list the columns of a MySQL table?
- Can we alter order of columns in MySQL?
- Can we use str_replace in MySQL?
- Can we use LIKE and OR together in MySql?
- How can we use nested transactions allowed in MySQL?
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?

Advertisements