Sunday, September 16, 2007

Scenario:
While retaining the IDENTITY column, how to merge two tables from different databases with same schema

Solution:
All you have to do is run the below mention query

SET IDENTITY_INSERT target_database.owner.target_table ON

INSERT INTO target_table (col1, col2, ..., colN)
SELECT FROM source_table(col1, col2, ..., colN)

SET IDENTITY_INSERT target_database.owner.target_table OFF


Have fun ;-)