MySQL Mysql向数据类型为enum的列添加新值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10047195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:51:11  来源:igfitidea点击:

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

mysqlddl

提问by Jeetendra Pujari

Say I have a mysql table, and I have a column of type enumand 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?

我将如何'e'使用alter table 语句向该集合添加值?

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

我想使用CONCAT.

回答by Asaph

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()在这种情况下使用。

回答by Muhammad Shahzad

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`;