Store primary key values in the database
when i copy data from one table to another, all primary key values are dumped. is there a way to preserve the values of the original table.
in the original table the primary key values (int) are not constant (deleted rows)
the other table has all the hardcoded values, so I need to keep the same values.
0
decon
a source
to share
1 answer
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
+5
a source to share