learning SQL

Posted on 2011-02-11
Medium Priority
Last Modified: 2012-05-11

I am using the following statement to copy records from a table called Main into another called Main1:

Insert into Main1
Select * from Main where tType = 'test';

However, I am getting the following Error:

Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'Main1' can only be specified when a column list is used and IDENTITY_INSERT is ON.

Question by:adamtrask
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
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 648 total points
ID: 34872170
'Main1' table contains an Identity column. so in your query you should mention other columns
Insert into Main1 (Column2, Column3, ...)
Select Column2, Column3, ... from Main where tType = 'test';
LVL 50

Assisted Solution

Lowfatspread earned 648 total points
ID: 34872189
you need to specify the list of column names excluding the identity column
(if you wish the identity column data to be re-assigned,,,
   or set identity insert on prior to executing the statement and set identity insert  off afterwards)

in any case it is always "best" to specify the list and order of column names rather than relying on *
to map columns between tables....

Accepted Solution

de2Zotjes earned 704 total points
ID: 34872211
You have a table that has a column with type IDENTITY, basically an autoincrementing field (mostly used to guarantee uniqueness of a record ).

You cannot assign values to that column.
You can try if this will work for you:
Insert into Main1
Select * from Main where tType = 'test';

Author Closing Comment

ID: 34872310
Thanks you

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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