Copy Data from One SQL Server Table to Other in Same Database Without Specifying Columns
Posted
by
Scott
on Stack Overflow
See other posts from Stack Overflow
or by Scott
Published on 2011-01-12T20:39:26Z
Indexed on
2011/01/12
20:53 UTC
Read the original article
Hit count: 181
In SQL Server there is the ability to INSERT
all of the data from one table into another using the following statement:
INSERT INTO TABLE1 SELECT * FROM TABLE2
When running this on a table with an identity column, even though we have run the command SET IDENTITY_INSERT TABLE1 ON
, we get the error:
An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON
This implies that we would have to list off all of the columns within the INSERT
in order for this to work properly. In the situation that we are in, we do not have access to the column names, only the list of the tables we need to copy over. Is there any way to get around this limitation?
© Stack Overflow or respective owner