tags:

views:

36

answers:

2

hello my friends, thanks for your attention to answer the questions. How can I merge two tables from different databases? Thanks again

A: 

If they have the same amount of columns, the columns have the same types and are in same order, you can simple do something like this (merges db1.a and db2.b into c of the currently selected db):

INSERT INTO c SELECT * FROM db1.a;
INSERT INTO c SELECT * FROM db2.b;
reko_t
A: 

Little vague in the question...Are you looking for information regarding getting the two databases talking to each other (linked server, replication maybe?)

Or I'll go out on a limb...you've got two tables in different databases and are looking at making it into one table going forward? The biggest 'gotcha' that I come across during database/table merging are key related issues. If the table simply has an ID column to keep each record unique, creating a new table and then loading data into the new table (allowing the ID to increment itself) is my preferred route (use insert statements like reko_t has written). If the table is using data columns to keep the record unique, then you'll need to determine if the data keys remain unique in a merged instance...if you're lucky, the key/key sets will be unique and you can pretty much mash the table together. Unlucky...you'll need to determine business rules on how to handle the duplicate keys.

M.E.