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 2 databases

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-07, 07:49
yaronr yaronr is offline
Registered User
 
Join Date: Jun 2007
Posts: 9
Merging 2 databases

I have 2 databases on the same datastore.
Both of them have the same structure, but different data.
Is there any easy way to merge between them?
Reply With Quote
  #2 (permalink)  
Old 07-15-07, 09:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
did you really mean 2 tables?

and could you please explain what "merge" means? do you want to end up with only one table? if so, which one?

also, are there primary keys in these tables? when the tables are merged, will there be duplicates?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-15-07, 16:33
yaronr yaronr is offline
Registered User
 
Join Date: Jun 2007
Posts: 9
i need merging between 2 databases that includes all the tables which they hold.
f.i: if I have in db_1 a table named: my_table, I will have a similar table with the same structure in db_2 with the same name and the same columns.
the tables might be different only in the data they hold, which means different primary keys for the rows. now i need a service or a command that can put all this data in one merged table, for all the tables in my new merged database.
In the next level requirement, I need also to do merge in rows that represent the same subject and that one of the rows is more updated, and should override the old row data in the merged table of the merged database.
Hope its more clear now....
Thanks
Reply With Quote
  #4 (permalink)  
Old 07-16-07, 04:25
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Create a new database, with the table in question, but remove all keys (or set duplicate key errors off). SELECT INTO from db1 and db2 INTO db3 all the info you need.
However, create a trigger on db3.table to only allow inserting of rows that don't exist or are newer.
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