Solved

An explicit value for the identity column in table

Posted on 2014-10-25
4
236 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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