If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Merging Two Databases - Auto Increment Keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-11, 17:25
ttmrb ttmrb is offline
Registered User
 
Join Date: Sep 2011
Posts: 2
Merging Two Databases - Auto Increment Keys

Hello. I've recently inherited a system that is a POS (no, not point of sale ). It has two separate app servers that do not share a database server. This means that the applications data resides in two separate databases.

I am in the process of significantly improving the hardware and software infrastructure and apart of that process is migrating the separate databases into one master database and then using replication to provide the high availability.

The problem I am having is I really have no idea how to merge these two databases into one. They have an identical schema but the data is different. The problem is with auto incrementing keys. Since the two databases were started empty, the auto incrementing keys started at 1 so I have primary keys of 1, 2, 3, etc. on both databases.

Does anyone know of a way, tool, etc of merging these two databases and appropriately changing the primary keys when merging so all of the data remains intact. Any help would be greatly appreciated. Thanks.
Reply With Quote
  #2 (permalink)  
Old 09-27-11, 18:51
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
Are you looking to combine the two original databases (so that every row from the two original databases ends up in the destination database), or merge the two original databases (so that only one set of unique rows ends up in the destination database)? There are a number of important considerations, and I think that a merge is what you really want but I'm not positive of that.

Either way, my first choice would be to replace the autonumbers with guids. This isn't always an option, but it sure makes life simpler! You can then just:

1) copy the working tables into a single table
2) add a guid column to every row
3) if merging, delete the duplicate rows except for the row with the lowest guid of the duplicated rows.
4) use the guid values going forward as the Primary Key.

If changing from autonumber to guid isn't a choice, you can do something very similar using autonumbers, you just have to dance better to make the details work!

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 09-27-11, 21:03
ttmrb ttmrb is offline
Registered User
 
Join Date: Sep 2011
Posts: 2
Thanks for the reply. In answer to your question, I am trying to combine the databases so that every row from both original databases ends up in the destination database.

I am not attached to the auto incrementing numbers in any way so I will have to look into migrating to uuids. Copying the working tables to a single table might be complicated since there are over 40 tables.

Thanks for the insight. This was very helpful.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On