I have a table where I need to change from "null" to "not null".
I have a table with following structure:
Created_By Created_Date_Time Modified_By Modified_Date_Time
NULL NULL -1 NULL
NULL NULL -1 NULL
NULL NULL -1 NULL
I need to change Modified_By from -1 to null.
I am trying with the following query but it gives me an error:
update BOM_Rules
set Modified_By = not null
Error:
Cannot insert the value NULL into column 'Modified_By', table 'dbo.BOM_Rules'; column does not allow nulls. UPDATE fails.
I am sure I am missing something important. Maybe alter table?
ALTER TABLE BOM_Rules
ALTER COLUMN Modified_By NVARCHAR(50) NOT NULL
I am using SQL2008R2.
NOT NULLvalue. That term is only used in DDL andWHEREclauses. You have to actually set a value if you want something to be not nullset Modified_By = not nullought to give you the errorIncorrect syntax near the keyword 'not'. as that is not valid syntax. Not an error about insertingNULL`Modified_Byfield contains-1, and that you want to change it to null. So, which is it?