Adding a Boolean column into an existing table

90,246

Solution 1

You have to define what you add - a column:

alter table chatuser  add column activerecord bool;

Solution 2

Lack COLUMN keyword

ALTER TABLE ChatUser ADD COLUMN ActiveRecord TinyInt(1)

Solution 3

Add with default value

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

Solution 4

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.

Solution 5

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;
Share:
90,246
uday gowda
Author by

uday gowda

Updated on July 09, 2022

Comments

  • uday gowda
    uday gowda almost 2 years

    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?