?
Solved

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

Posted on 2004-09-08
4
Medium Priority
?
219 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

764 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