MySQL 将布尔列添加到现有表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12033103/
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
Adding a Boolean column into an existing table
提问by uday gowda
I'm trying to add a boolean column into an existing table
我正在尝试将布尔列添加到现有表中
alter table chatuser add activerecord bool;
alter table chatuser add activerecord boolean;
where activerecord is my boolean column
其中 activerecord 是我的布尔列
Neither of these queries are working. How can I add a boolean column to an existing table?
这些查询都不起作用。如何将布尔列添加到现有表中?
回答by juergen d
You have to define what you add - a column:
您必须定义您添加的内容 - 一列:
alter table chatuser add column activerecord bool;
回答by John Woo
Lack COLUMNkeyword
缺少COLUMN关键字
ALTER TABLE ChatUser ADD COLUMN ActiveRecord TinyInt(1)
回答by sandeep kumar
Add with default value
添加默认值
ALTER TABLE my_table ADD COLUMN new_field TinyInt(1) DEFAULT 0;
回答by Sami
ALTER TABLE chatuser ADD activerecord BOOLEAN
No need of word 'column'
不需要“列”这个词
Your second query is perfectly all right (at least) in mysql.
您的第二个查询在 mysql 中完全没问题(至少)。
Try:
尝试:
select * from chatuser;
If you are unable to see results, check your mysql server or other things, not the
query and, if above select query works, and you do not have activerecordnamed column already, I bet your query will work.
如果您看不到结果,请检查您的 mysql 服务器或其他内容,而不是查询,如果上述选择查询有效,并且您还没有activerecord命名列,我敢打赌您的查询将有效。
回答by Alan B. Dee
I found that on Microsoft SQL the following was invalid:
我发现在 Microsoft SQL 上以下是无效的:
ALTER TABLE meTable ADD COLUMN someBoolCol TinyInt;
Omitting the "column" keyword worked:
省略“列”关键字有效:
ALTER TABLE meTable ADD someBoolCol TinyInt;

