Not sure if I understand you correctly: You want to copy all the data from TABLE2, but make sure that TABLE2.similiarId is not alredy in TABLE1.id, maybe this is the solution for your problem:
DECLARE @idmax INT SELECT @idmax = MAX(id) FROM TABLE1 INSERT INTO TABLE1 (id, id2, col1, col2) SELECT similiarId + @idmax, similiarId2, similiarCol1, similiarCol2 FROM TABLE2
Now the insertion will not fail due to a violation of the primary key, because each inserted identifier will be larger than the id that was alredy there.
Jarek bielicki
source share