Cannot change column to Not Null: Cannot insert the value NULL into column '', table '.dbo.Tmp_'; column does not allow nulls.

Posted By  RRaveen On 20 Aug 2010 12:08:43
emailbookmarkadd commentsprint
No of Views:4357
Bookmarked:0 times
Votes:0 times

Introduction

In sql server 2008/ 2005, when you are modify column in table the from null column to non null column, you will get this error

'<TableName>' table
- Unable to modify table. 
Cannot insert the value NULL into column '<ColumnName>', table 'Database.dbo.Tmp_<TableName>'; column does not allow nulls. INSERT fails.
The statement has been terminated.

 

This is occurs if there is already data in this table and this column contains nulls.

Solution

If this column int type, then you can set the - 1 to that column, then it does not null. If char type column then you can set empty values as well. for update you can use the T-SQL.

thank you for reading.

Sign Up to vote for this article
Other popular Tips/Tricks
    In this tips, I will explain how to ALTER or ADD two or more columns in to table by t-sql script.
    Published Date : 25/Mar/2011
    A very important feature of SQL Server 2008 is that we can enable CDC(Change Data capture) on database or table.We can track the database had CDC enabled by querying IS_CDC_ENABLED column
    Published Date : 17/Jan/2011
    A very important feature of SQL Server 2008 is that we can enable CDC(Change Data capture) on database or table.We can track the database had CDC enabled by querying IS_CDC_ENABLED column
    Published Date : 17/Jan/2011
    This is the third tips date related function in sql server. In this I going to show you how to use DATEDIFF() function in sql server. The DATEDIFF () is useful to get the specified date part between two dates
    Published Date : 16/Dec/2010
    The DATEADD function is a powerful built-in function sql server to add dates in different way and types. So I would like to explore in this tip how we can use the DATEADD function for different purpose.
    Published Date : 12/Dec/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top