Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Boolean column into an existing table

Tags:

mysql

alter

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?

like image 971
uday gowda Avatar asked Aug 20 '12 06:08

uday gowda


People also ask

How do I add a boolean column to a table in SQL?

ALTER TABLE table_name ALTER COLUMN col_name SET NOT NULL; Or you can put them all together in a single statement: ALTER TABLE table_name ADD COLUMN “col_name” BOOLEAN DEFAULT FALSE; This way it might take longer if the operation is huge.

How do you add a boolean value to a table?

Since MySQL always use TINYINT as Boolean, we can also insert any integer values into the Boolean column. Execute the following statement: Mysql> INSERT INTO student(name, pass) VALUES('Miller',2);

How do I add a boolean datatype in SQL?

You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.

How do I add a column to an existing table?

In Object Explorer, right-click the table to which you want to add columns and choose Design. Select the first blank cell in the Column Name column. Type the column name in the cell. The column name is a required value.


2 Answers

You have to define what you add - a column:

alter table chatuser  add column activerecord bool; 
like image 129
juergen d Avatar answered Sep 20 '22 13:09

juergen d


Lack COLUMN keyword

ALTER TABLE ChatUser ADD COLUMN ActiveRecord TinyInt(1) 
like image 40
John Woo Avatar answered Sep 18 '22 13:09

John Woo