How to modify "null" to "not null" in sql
database, sql, sql-server, sql-server-2008
Solution
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
Problem
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.