Solved

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

Posted on 2004-09-08
4
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

705 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