SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Try to add a column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Karim174
Starting Member

5 Posts

Posted - 12/03/2013 :  06:02:43  Show Profile  Reply with Quote
Hello SQL Guru's

Im trying to add a column in a table but i get the following error;

Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'incident_id', table 'DWH.dbo.incident'; column does not allow nulls. INSERT fails.

I use the following syntax to add the column ( I copy a previous column from a other table ) ;

GO
INSERT INTO DWH.DBO.incident (incident_ref)
SELECT incident_ref
FROM incident;
GO


I create column as follow;

alter table incident
add incident_ref varchar(25)

See picture1 how my table original table looks

and picture2 how my table look like now





SQL GETTING A DREAM

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/03/2013 :  06:30:05  Show Profile  Reply with Quote
I cant view the image
But error message suggests you're trying to insert NULL value to 'incident_id' column which is declared as NOT NULL and hence its failing. So either make it as NULLable or if it has to have a value always check the query on why its getting some NULL values.

Also the insert statement above doesnt include this column. So unless its declared as an IDENTITY column or has a default constraint, INSERT will break if 'incident_id' is NOT NULL.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000