Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

learning SQL

Posted on 2011-02-11
4
Medium Priority
?
311 Views
Last Modified: 2012-05-11
Hi,

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.

Thanks
0
Comment
Question by:adamtrask
[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
4 Comments
 
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';
0
 
LVL 50

Assisted Solution

by:Lowfatspread
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....
0
 
LVL 6

Accepted Solution

by:
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:
SET IDENTITY_INSERT Main1 ON;
Insert into Main1
Select * from Main where tType = 'test';
SET IDENTITY_INSERT Main1 OFF;
0
 

Author Closing Comment

by:adamtrask
ID: 34872310
Thanks you
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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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

598 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