Solved

An explicit value for the identity column in table

Posted on 2014-10-25
4
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Conditional WHERE clause 3 49
If in a where clause in t-sql 7 53
T-SQL: Need to trim a single leading space 7 63
What does "Between" mean? 6 49
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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