Solved

learning SQL

Posted on 2011-02-11
4
304 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
Comment Utility
'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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks you
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

11 Experts available now in Live!

Get 1:1 Help Now