Link to home
Start Free TrialLog in
Avatar of higgsy
higgsy

asked on

Keeping Int Identity values when transferring data between databases

Hi,

Ive got two databases on my server. One is the production and the other is development (althoug that is to be changed around).

The development database has changed alot from the production, therefore i need to extract the data out of the production one and insert it into the development one, taking care with the SQL to put values in all the new fields that have been created etc...

The problem is that when i use query analyzer to transfer for example, all the data from one users table to another, in the development database each row is given a new unique value. Although normallly this would be fine, i really need to keep the records original ID as other tables all over the database depend on this.

Is there a method of doing this??

Thanks in advance

Al Higgs
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also using DTS you can do a Database copy and it has the option of inserting identity values.  Behind the scenes it does a SET IDENTITY_INSERT ON.  
When inserting columns into a table with IDENTITY_INSERT ON the column list must be specified for the destination table.

i.e.

Insert mytable (col1, col2, col3, ...)  SELECT * from old_table