Monday, March 12, 2012

Importing Data With Duplicate Keys

I'm trying to merge two Access databases into one SQL server database. I have 3 tables that are all related with primary and foreign keys.

When I try to import my second set of 3 tables I get errors about the keys already existing in the database. Is there any way to force SQL server to assign new keys while preserving my existing relationships? Thanks!No.
You will have to update the keys in two or your Access databases to ensure that no records from the three databases conflict. And you will likely also have to deal with issues where you have identical records in each database that should be merged rather than duplicated (such as in lookup lists...).
Or, another possible solutions is to load the data from separate databases into separate versions of the same SQL Server table, assigning new GUID identifiers simultaneously. The three tables can then be merged using GUIDs rather than the integer/identity values you probable have right now. Note that you will still need to update foreign keys in related tables to reference the new GUIDs.
These things are all just part of a DBA's day...|||Blah, I knew this wouldn't be fun. Thanks for the info.|||want to show us some DDL and sample data of what the problem is?|||I never said it wouldn't be fun. I just said it is what we DBAs do all day.

Every day.

Day in, day out...

Day after day after day after day...

Hell, it's a blast.|||i have 2 contradictory seanisms on this...

I sometimes tell the bellachers around here

"if you ain't having fun, go do something else for a living"

and when they complain sometimes I tell them...

"if it was easy and fun they would not pay us money to do it"|||I figured out an easy way to do this. Basically I check the ID of the last field in my master database. Before I import data I remove the primary key restriction and run an update query whereby I add that last number to each of the existing ID numbers. This automatically iterates my keys to the new start point I need.|||Fine. Now make sure you update all the foreign key references to the primary keys you just modified...|||I forgot to mention to do that immediately afterward, thanks.|||sounds like a total fubar process

how does a surrogate key have any meaning?|||I admit, it's not the best solution--if I understood what you said. But we're only talking about three tables.

No comments:

Post a Comment