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.

Share:
12,578
shibly
Author by

shibly

Updated on August 03, 2022

Comments

  • shibly
    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
    shibly over 12 years
    boolean default true and boolean default 1 , are they same ?
  • shibly
    shibly over 12 years
    modify columnname and change columnname , are they similar ?
  • shibly
    shibly over 12 years
    What is prefered in MyISM database engine ?
  • Johan
    Johan over 12 years
    Nonsense, boolean is tinyint(1), there is no difference.
  • Bohemian
    Bohemian over 12 years
    modify alters just the column datatype. change alters the column datatype and also renames the column (not needed here).