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
Solved

learning SQL

Posted on 2011-02-11
4
307 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
4 Comments
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 162 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 162 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 176 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
MySQL left join performance 4 44
How to Generate log or file on inserting duplicate records in mysql 6 51
update joined tables 2 55
two ways encryption with php 3 37
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 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