Solved

learning SQL

Posted on 2011-02-11
4
305 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

17 Experts available now in Live!

Get 1:1 Help Now