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')
.
假设我有一个mysql表,并且我有一个类型为enum的列,该列已经定义了一组值,如enum('a','b','c','d')。
How would i add a value of 'e'
to this set using alter table statement?
如何使用alter table语句向该集合添加'e'值?
And I want to append the new value to the end of it using CONCAT
.
我想使用CONCAT将新值附加到它的末尾。
2 个解决方案
#1
37
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.
在这种情况下,你真的不想使用CONCAT()。
#2
0
If you want to add default value and also want after a specific column for enum, try this query:
如果要添加默认值并且还想在枚举的特定列之后,请尝试以下查询:
Alter table `your_table`
Add column `visible_on` enum('web','mobile','both') default 'both'
After `your_column`;
#1
37
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.
在这种情况下,你真的不想使用CONCAT()。
#2
0
If you want to add default value and also want after a specific column for enum, try this query:
如果要添加默认值并且还想在枚举的特定列之后,请尝试以下查询:
Alter table `your_table`
Add column `visible_on` enum('web','mobile','both') default 'both'
After `your_column`;