Reputation: 609
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.
Upvotes: 2
Views: 5732
Reputation: 1629
It sounds like the Modified_By column does not allow nulls. Try altering the column to allow nulls:
ALTER TABLE BOM_Rules
ALTER COLUMN Modified_By NVARCHAR(50) NULL
Upvotes: 6