开发者

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

开发者 https://www.devze.com 2023-04-01 20:35 出处:网络
I\'m trying something like this => alter table tablenam开发者_开发百科e modify columnname \"boolean\" default 1 NOT NULL;

I'm trying something like this =>

alter table tablenam开发者_开发百科e 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

Is this what you are after?


alter table tablename modify columnname boolean default true NOT NULL;

Don't put quotes around boolean.

I tested this on a column that was int and it worked.


instead of boolean use TINYINT(1). This is preferred on InnoDB database engine

0

精彩评论

暂无评论...
验证码 换一张
取 消