简体   繁体   English

创建/更改mysql表的列时如何创建布尔列并分配值1?

[英]How can i create boolean column and assign value 1 when creating/altering a column of a mysql table?

I'm trying something like this => 我正在尝试类似=>

alter table tablename modify columnname "boolean" default 1 NOT NULL;

Which is the correct format to create boolean column ? 创建布尔列的正确格式是哪种?

ALTER TABLE tablename CHANGE columnname columnname BOOLEAN DEFAULT '1' NOT NULL

这就是你追求的吗?

alter table tablename modify columnname boolean default true NOT NULL;

Don't put quotes around boolean . 不要在boolean加上引号。

I tested this on a column that was int and it worked. 我在一个int列上对其进行了测试,并且该列有效。

instead of boolean use TINYINT(1). 而不是布尔,请使用TINYINT(1)。 This is preferred on InnoDB database engine 在InnoDB数据库引擎上首选

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM