How to add a boolean datatype column to an existing table in sql?
In SQL SERVER it is BIT
, though it allows NULL
to be stored
ALTER TABLE person add [AdminApproved] BIT default 'FALSE';
Also there are other mistakes in your query
When you alter a table to add column no need to mention
column
keyword inalter
statementFor adding default constraint no need to use
SET
keywordDefault value for a
BIT
column can be('TRUE' or '1')
/('FALSE' or 0)
.TRUE
orFALSE
needs to mentioned asstring
not as Identifier
In phpmyadmin, If you need to add a boolean datatype column to an existing table with default value true:
ALTER TABLE books
isAvailable boolean default true;
The answer given by Pரதீப் creates a nullable bool, not a bool, which may be fine for you. For example in C# it would create: bool? AdminApproved
not bool AdminApproved
.
If you need to create a bool (defaulting to false):
ALTER TABLE person
ADD AdminApproved BIT
DEFAULT 0 NOT NULL;