Solved

Best way to move parent child data from one db to another

Posted on 2004-09-08
4
210 Views
Last Modified: 2012-06-27
What is the best way to move parent child(multiple) data to from one db to another using code C# or t-SQL in one transaction (if this is a good idea)
 
0
Comment
Question by:vinny45
  • 3
4 Comments
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 12009162
Are there foreign keys and/or primary keys defined on the tables? Do they autonumber (IDENTITY)?
0
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 12009165
In other words, could you script out the tables with Enterprise Manager and post them here?
0
 

Author Comment

by:vinny45
ID: 12009322
yes they do autonumber, iam not sure what the table looks like yet, but its pretty much standard stuff with primary and foriegn keys
0
 
LVL 18

Accepted Solution

by:
SjoerdVerweij earned 500 total points
ID: 12009467
in that case, in the destination database:

begin tran

delete from table1

set identity_insert table1 on

insert into table1(...list of columns...) select ...list of columns... from sourcedatabase..table1

set identity_insert table1 off

...etc.

commit tran

Make sure you go from bottom to top in order, e.g. if table1 references table2 which references table3, go

delete table1, delete table2, delete table3
insert table3, insert table2, insert table1

0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now