Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Add a new value to a column of data type enum

Tags:

mysql

ddl

Say I have a mysql table, and I have a column of type enum and that column has defined set of values like enum('a','b','c','d').

How would i add a value of 'e' to this set using alter table statement?

And I want to append the new value to the end of it using CONCAT.

like image 719
Jeetendra Pujari Avatar asked Apr 06 '12 17:04

Jeetendra Pujari


People also ask

Can you add values to enum?

You cannot create an object of an enum explicitly so, you need to add a parameterized constructor to initialize the value(s). The initialization should be done only once. Therefore, the constructor must be declared private or default. To returns the values of the constants using an instance method(getter).

How do you alter an enum?

Alter type –We can alter enum type after creation, we can modify the enum type by using the alter type command. We can add a new value into the enum data set to use the same into the table. Add value –This is defined as add a new value to the enum type by using the alter type command.

Can enum have multiple values MySQL?

Any idea to store multiple values in ENUM data type ? ENUM is a value type, not a set or array type. Instead of storing arrays of values, it would be better to normalize your data so that all the normal querying and integrity features in MySQL can be used.

Is enum a data type in MySQL?

The ENUM data type in MySQL is a string object. It allows us to limit the value chosen from a list of permitted values in the column specification at the time of table creation. It is short for enumeration, which means that each column may have one of the specified possible values.


1 Answers

Unfortunately, you need to re-list all the existing enum values when adding a new value to the the enum.

ALTER TABLE mytable MODIFY COLUMN mycolumn ENUM('a','b','c','d','e');

You don't really want to use CONCAT() in this situation.

like image 109
Asaph Avatar answered Oct 19 '22 07:10

Asaph