Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

An explicit value for the identity column in table

Posted on 2014-10-25
4
Medium Priority
?
245 Views
Last Modified: 2014-10-26
I am getting the following error:
Msg 8101, Level 16, State 1, Line 8
An explicit value for the identity column in table 'CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue' can only be specified when a column list is used and IDENTITY_INSERT is ON.
The code I have is listed below:
Thanks in advance for any help given.
SET identity_insert ProductVariantAttributeValue ON
SELECT * 
INTO CorpWear265_Restore_TestAlt..table1_originall 
FROM CorpWear265_Restore_Test.dbo.ProductVariantAttributeValue
DELETE CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue
USE CorpWear265_Restore_TestAlt
/*SET identity_insert ProductVariantAttributeValue OFF*/
INSERT INTO CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue 
SELECT * 
FROM CorpWear265_Restore_TestAlt..table1_originall
DROP TABLE CorpWear265_Restore_TestAlt..table1_originall
USE CorpWear265_Restore_TestAlt
SET identity_insert ProductVariantAttributeValue OFF
GO
SELECT TOP 14000 [Id]
      ,[ProductVariantAttributeId]
      ,[Name]
      ,[PriceAdjustment]
      ,[WeightAdjustment]
      ,[IsPreSelected]
      ,[DisplayOrder]
  FROM [CorpWear265_Restore_TestAlt].[dbo].[ProductVariantAttributeValue]
 
  /*
  where Name Like '%!%'
  */
  Go

Open in new window

0
Comment
Question by:homeshopper
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 40404198
Try rearranging so your Set Identity_insert ... line is after your USE line.
0
 

Author Comment

by:homeshopper
ID: 40404503
Thank you for your suggestion. The code I now have is below:
But it still gives the same error:
Msg 8101, Level 16, State 1, Line 7
An explicit value for the identity column in table 'CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue' can only be specified when a column list is used and IDENTITY_INSERT is ON.
SELECT * 
INTO CorpWear265_Restore_TestAlt..table1_originall 
FROM CorpWear265_Restore_Test.dbo.ProductVariantAttributeValue
DELETE CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue
USE CorpWear265_Restore_TestAlt
SET identity_insert ProductVariantAttributeValue ON
INSERT INTO CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue 
SELECT * 
FROM CorpWear265_Restore_TestAlt..table1_originall
DROP TABLE CorpWear265_Restore_TestAlt..table1_originall
USE CorpWear265_Restore_TestAlt
GO

Open in new window

0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 40404768
Oh, "... when a column list is used and..."

That's the piece we're missing.

INSERT INTO CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue
(Field1, Field2, ... Fieldn)
SELECT Field1, Field2, ... Fieldn
FROM CorpWear265_Restore_TestAlt..table1_originall
0
 

Author Comment

by:homeshopper
ID: 40404782
Thanks, it now works.
The final code I have is listed below for others to see:
SELECT * 
INTO CorpWear265_Restore_TestAlt..table1_originall 
FROM CorpWear265_Restore_Test.dbo.ProductVariantAttributeValue
DELETE CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue
USE CorpWear265_Restore_TestAlt
SET identity_insert ProductVariantAttributeValue ON
INSERT INTO CorpWear265_Restore_TestAlt.dbo.ProductVariantAttributeValue 
	   ([Id]
      ,[ProductVariantAttributeId]
      ,[Name]
      ,[PriceAdjustment]
      ,[WeightAdjustment]
      ,[IsPreSelected]
      ,[DisplayOrder])
SELECT [Id]
      ,[ProductVariantAttributeId]
      ,[Name]
      ,[PriceAdjustment]
      ,[WeightAdjustment]
      ,[IsPreSelected]
      ,[DisplayOrder]
FROM CorpWear265_Restore_TestAlt..table1_originall
DROP TABLE CorpWear265_Restore_TestAlt..table1_originall
USE CorpWear265_Restore_TestAlt
GO

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question