How can i create boolean column and assign value 1 when creating/altering a column of a mysql table?
12,578
Solution 1
ALTER TABLE tablename CHANGE columnname columnname BOOLEAN DEFAULT '1' NOT NULL
Is this what you are after?
Solution 2
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.
Author by
shibly
Updated on August 03, 2022Comments
-
shibly over 1 year
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 ?
-
shibly over 12 yearsboolean default true and boolean default 1 , are they same ?
-
shibly over 12 yearsmodify columnname and change columnname , are they similar ?
-
shibly over 12 yearsWhat is prefered in MyISM database engine ?
-
Johan over 12 yearsNonsense, boolean is tinyint(1), there is no difference.
-
Bohemian over 12 years
modify
alters just the column datatype.change
alters the column datatype and also renames the column (not needed here).