I have a table called person in my database. I want to add another column to the same table and it's a Boolean datatype column. I have tried following queries but it says syntax error near default. I know this is a common and there are lot of answers. I have tried many of them and couldn't figure out to make it work. So please help me.
queries I have tried
ALTER TABLE person add column "AdminApproved" BOOLEAN SET default FALSE;
ALTER TABLE person alter column "AdminApproved" BOOLEAN SET default FALSE;
I have tried without SET key word too.
4条答案
按热度按时间pokxtpni1#
In SQL SERVER it is
BIT
, though it allowsNULL
to be storedAlso there are other mistakes in your query
column
keyword inalter
statementSET
keywordBIT
column can be('TRUE' or '1')
/('FALSE' or 0)
.TRUE
orFALSE
needs to mentioned asstring
not as Identifier8i9zcol22#
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
notbool AdminApproved
.If you need to create a bool (defaulting to false):
sy5wg1nm3#
In phpmyadmin, If you need to add a boolean datatype column to an existing table with default value true:
vx6bjr1n4#
There are two ways that you can do it.