Copy Data from One SQL Server Table to Other in Same Database Without Specifying Columns
- by Scott
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?