all groups > sql server programming > may 2005 >
You're in the

sql server programming

group:

alter table



alter table Big D
5/31/2005 10:07:06 PM
sql server programming: Using the alter table command i create a new column on a existing table.
When I creater this new column I want to set the default value as 0. For
some reason the column name is null.

SQL statement:

ALTER TABLE [dbo].[DMINFORMATION] WITH NOCHECK ADD
[ACTIVEFLAGS] [bit] DEFAULT ((0))

Any ideas or the issue with SQL statement?

Thanks,
Big D

Re: alter table Steve Kass
5/31/2005 11:29:59 PM
Big D,

The default value becomes 0 for new rows, but I'll guess what
you want is for the value of this column in existing rows to be 0. In
order to apply a DEFAULT to existing rows, add WITH VALUES to
the statement (and remove NOCHECK, because it doesn't make any
sense for a DEFAULT constraint).

ALTER TABLE [dbo].[DMINFORMATION]
ADD [ACTIVEFLAGS] [bit] DEFAULT 0 WITH VALUES

Steve Kass
Drew University


[quoted text, click to view]
AddThis Social Bookmark Button