SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Appending data having trouble with foreign keys


Appending data having trouble with foreign keys

Author
Message
ryetimothy
ryetimothy
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 89
Someone I work with created the wrong ODBC connection and entered data in the wrong database (old copy on an old server that's about to be decommissioned) and I need to move the data to the new location. Transferring most of the data will be a breeze but there's two tables that are causing me problems because one of the table is linked to the other using a foreign key. I'm concerned about maintaining the relational integrity of the tables and updating the foreign key in the child table based on the new primary key in the parent table. Could anyone give me some advice on how to proceed?
Eirikur Eiriksson
Eirikur Eiriksson
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41796 Visits: 19517
ryetimothy (8/27/2014)
Someone I work with created the wrong ODBC connection and entered data in the wrong database (old copy on an old server that's about to be decommissioned) and I need to move the data to the new location. Transferring most of the data will be a breeze but there's two tables that are causing me problems because one of the table is linked to the other using a foreign key. I'm concerned about maintaining the relational integrity of the tables and updating the foreign key in the child table based on the new primary key in the parent table. Could anyone give me some advice on how to proceed?


Quick thought (if I got this right), copy both tables without the constraints to the correct server/database. Then run a query that returns any entries violating the foreign key constraints. If "three green" then reinstate the constraints.
Cool
ryetimothy
ryetimothy
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 89
Pretty sure there won't be a problem with violations because the database in the new location hasn't been modified since it was migrated.

Possibly dumb questions here: I import the parent table first and then the child table? Are the connections between the child table and the parent table recreated or is there something I have to do after the import to make sure to maintain referential integrity? What happens if there are key violations?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search