MySQL 将新的枚举列添加到现有表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30139813/
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 20:59:22  来源:igfitidea点击:

Adding new enum column to an existing table

mysqlenumsalter

提问by max85

I'm trying to add a gendercolumn to my table with this query:

我正在尝试gender使用此查询向我的表中添加一列:

ALTER TABLE QRCodeUser ADD gender CHAR(1) enum('M','F') NOT NULL;

I get this error:

我收到此错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'enum('M','F') NOT NULL' at line 1

#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“enum('M','F') NOT NULL'附近使用的正确语法

What's my mistake?

我的错误是什么?

回答by dsharew

Try this (you dont need to specify the size, char(1)) :

试试这个(你不需要指定大小,char(1)):

ALTER TABLE QRCodeUser ADD gender  enum('M','F') NOT NULL;

回答by Krishnamurthy Kulkarni

Correct usage of syntax:

正确使用语法:

ALTER TABLE table_name ADD column_name  enum(`field1`,`field2`,...);