uday gowda
uday gowda

Reputation: 619

Adding a Boolean column into an existing table

I'm trying to add a boolean column into an existing table

alter table chatuser add activerecord bool;
alter table chatuser add activerecord boolean;

where activerecord is my boolean column

Neither of these queries are working. How can I add a boolean column to an existing table?

Upvotes: 34

Views: 111280

Answers (5)

Sandeep Sherpur
Sandeep Sherpur

Reputation: 2802

Add with default value

ALTER TABLE my_table ADD COLUMN new_field TinyInt(1) DEFAULT 0;

Upvotes: 14

Alan B. Dee
Alan B. Dee

Reputation: 5616

I found that on Microsoft SQL the following was invalid:

ALTER TABLE meTable ADD COLUMN someBoolCol TinyInt;

Omitting the "column" keyword worked:

ALTER TABLE meTable ADD someBoolCol TinyInt;

Upvotes: 2

Sami
Sami

Reputation: 8429

ALTER TABLE chatuser ADD activerecord BOOLEAN

No need of word 'column'

Your second query is perfectly all right (at least) in mysql.

Try:

select * from chatuser;

If you are unable to see results, check your mysql server or other things, not the query and, if above select query works, and you do not have activerecord named column already, I bet your query will work.

Upvotes: 2

John Woo
John Woo

Reputation: 263733

Lack COLUMN keyword

ALTER TABLE ChatUser ADD COLUMN ActiveRecord TinyInt(1)

Upvotes: 17

juergen d
juergen d

Reputation: 204766

You have to define what you add - a column:

alter table chatuser  add column activerecord bool;

Upvotes: 54

Related Questions