cola
cola

Reputation: 12466

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 ?

Upvotes: 2

Views: 12626

Answers (3)

Hungry Mind
Hungry Mind

Reputation: 113

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

Upvotes: 0

Paul Walls
Paul Walls

Reputation: 6044

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

Is this what you are after?

Upvotes: 4

Bohemian
Bohemian

Reputation: 425063

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.

Upvotes: 3

Related Questions