Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm having a weird issue with IDENTITY_INSERT & am at a loss. Can anyone see what I'm missing?

I’m getting an error when trying to execute the following statements complaining that IDENTITY_INSERT must be on in order for the insert to occur, but I am turning it on.

SET IDENTITY_INSERT Thompson_GDM.dbo.employees ON    
GO

INSERT INTO Thompson_GDM.dbo.employees    
SELECT [EmployeeId],    
       [AssignmentId],    
       [more columns...]    
FROM TMLAVSQLBIS.ThompsonMachinery.dbo.Employees;    
GO

SET IDENTITY_INSERT Thompson_GDM.dbo.employees OFF    
go

The error message is "An explicit value for the identity column in table ‘Thompson_GDM.dbo.employees’ can only be specified when a column list is used and IDENTITY_INSERT is ON."

As you can see, I am using a column list & it matches the table layout. I have checked it several times & it does match

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It needs a column list after the INSERT INTO (before the SELECT):

SET IDENTITY_INSERT Thompson_GDM.dbo.employees ON    
GO

INSERT INTO Thompson_GDM.dbo.employees([EmployeeId],    
       [AssignmentId],    
       [more columns...] )    
SELECT [EmployeeId],    
       [AssignmentId],    
       [more columns...]    
FROM TMLAVSQLBIS.ThompsonMachinery.dbo.Employees;    
GO

SET IDENTITY_INSERT Thompson_GDM.dbo.employees OFF    
go

Obviously the "more columns" would be the actual columns

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading