Monday 10 June 2019

MSSQL - Fix Error - 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 'SomeNewColumn' cannot be added to non-empty table 'Product' because it does not satisfy these conditions.

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 'SomeNewColumn' cannot be added to non-empty table 'Product' because it does not satisfy these conditions.


Watch this example on YouTube

 


To fix it replace

Alter Table [Product]
ADD SomeNewColumn bit Not Null
GO


with

Alter Table [Product]
ADD SomeNewColumn bit Not Null Default 0
GO 

No comments:

Post a Comment