views:

50

answers:

1

when i copy data from one table to another all the primary key values are resetted. is there a way to keep the values of the original table.

in the original table the primary key values (int) are not continual (deleted rows)

another table has all the values hardcoded thats why i need to keep the same values.

+5  A: 

You can do this by setting IDENTIY_INSERT ON

If both tables have the same columns, you can do something like the following:

SET IDENTITY_INSERT Table2 ON
INSERT Table2(pkId, Field2, Field3,...)
SELECT pkId, Field2,Field3,... FROM Table1
SET IDENTITY_INSERT Table2 OFF
ichiban