
- 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 do I add more members to my ENUM - type column in MySQL?
You can use alter command. The syntax is as follows −
ALTER TABLE yourTableName MODIFY COLUMN yourColumNam enum(yourOldValue1,yourOldValue2,....N,yourNewValue1,yourNewValue2,....N);
To understand the above syntax, let us first create a table. The query to create a table is as follows −
mysql> create table EnumDemo -> ( -> AllColors enum('RED','GREEN') -> ); Query OK, 0 rows affected (0.66 sec)
Now you have two members in AllColors of enum type. If you want to add more members to your enum type, use the following query −
mysql> alter table EnumDemo -> modify column AllColors enum('RED','GREEN','YELLOW','BLUE'); Query OK, 0 rows affected (0.17 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the structure of the table whether it is updated with new members or not. The query is as follows −
mysql> SHOW CREATE TABLE EnumDemo;
Output
+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ | EnumDemo | CREATE TABLE `enumdemo` (`AllColors` enum('RED','GREEN','YELLOW','BLUE') DEFAULT NULL ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Yes, we have two new members now i.e. YELLOW and BLUE.
- Related Articles
- Add a new value to a column of data type enum in MySQL?
- How do I update the decimal column to allow more digits in MySQL?
- How can I insert default value in MySQL ENUM data type?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- How do I force the column alias to be of specific data type in MySQL?
- Do MySQL Can Enum type values contain spaces in it?
- How Should I do Digital Marketing for My Restaurant to Attract More Customers?
- How do I alter table column datatype on more than 1 column at a time in MySql?
- How do I add to each row in MySQL?
- How to add time in a MySQL column set with type DATETIME?
- Comparing enum members in C#
- How do I cast a type to a BigInt in MySQL?
- Comparing enum members in Java\n
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- How can I add debugging code to my JavaScript?

Advertisements