August 16, 2011 at 8:35 am
I am trying to add NOT NULL column to existing table.
when I try to add it throws an error.
Msg 4901, Level 16, State 1, Line 1
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'test_Column' cannot be added to non-empty table 'test_1' because it does not satisfy these conditions.
thanks in advance,
August 16, 2011 at 8:40 am
Danzz (8/16/2011)
I am trying to add NOT NULL column to existing table.when I try to add it throws an error.
Msg 4901, Level 16, State 1, Line 1
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'test_Column' cannot be added to non-empty table 'test_1' because it does not satisfy these conditions.
thanks in advance,
the error kind of explains it...but what you need to do is add a default value to the command you are using to add the column:
ALTER TABLE dbo.YOURTABLE
ADD MyNewColumn INT NOT NULL DEFAULT(42)
Lowell
August 16, 2011 at 8:50 am
Thanks for the quick replay,
But there are 1 million rows in the table, adding DEFAULT value is a best pratice.
Is there any alternative solutions possiable?
August 16, 2011 at 12:15 pm
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply