Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Try to add a column

Author  Topic 

Karim174
Starting Member

5 Posts

Posted - 2013-12-03 : 06:02:43
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

52326 Posts

Posted - 2013-12-03 : 06:30:05
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
   

- Advertisement -