33

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?

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
uday gowda
  • 609
  • 3
  • 10
  • 16

5 Answers5

52

You have to define what you add - a column:

alter table chatuser  add column activerecord bool;
juergen d
  • 201,996
  • 37
  • 293
  • 362
17

Lack COLUMN keyword

ALTER TABLE ChatUser ADD COLUMN ActiveRecord TinyInt(1)
John Woo
  • 258,903
  • 69
  • 498
  • 492
14

Add with default value

ALTER TABLE my_table ADD COLUMN new_field TinyInt(1) DEFAULT 0;
Sandeep Sherpur
  • 2,418
  • 25
  • 27
2
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.

TankorSmash
  • 12,186
  • 6
  • 68
  • 106
Sami
  • 8,168
  • 9
  • 66
  • 99
2

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;
Alan B. Dee
  • 5,490
  • 4
  • 34
  • 29