Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    9

    Unanswered: 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?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •