Solved

An explicit value for the identity column in table

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now