Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  129 Posts | 0 Stories | 874 Comments | 677 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

When modifying a table SQL Server (2005) and unchecking a column's 'Allow Nulls' (ie trying to make the column Not Null) the following error may occur:
'<tablename>' table
- Unable to modify table. 
Cannot insert the value NULL into column '<columnname>', table '<dbname>.dbo.Tmp_<tablename>'; column does not allow nulls. INSERT fails.
The statement has been terminated.
This occurs if there is already data in this table and this column contains nulls.
 
The solution is to simply update the data in this table so that this column does not contain nulls then change the column to not null.  eg if this column was of type int you could do this:

UPDATE [<dbname>].[dbo].[<tablename>]
    SET [<integercolumnname] = -1

posted on Thursday, May 29, 2008 9:05 PM