473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I Merge two databases?

I have two databases with each one on a different server. I can copy
both databases to the same server with no problems. But how do I merge
them?

This is what I came up with so far but how do I do the same process for
multiple rows and tables?

IF NOT EXISTS (SELECT tmp_DB1.dbo.tb1.key1 FROM tmpDB1.dbo.tb1 WHERE
tmp_DB1.dbo.tb1.key1 = tmp_DB2.dbo.tb1.key1)
INSERT INTO tmp_DB1.dbo.tb1 (<all fields>)
VALUES (<all fields>)
Thanks in advance.

Jul 20 '05 #1
2 1521
You probably want to do something like this (insert into a new table only
the rows that don't already exist):

INSERT INTO DB1.dbo.TargetTable (key_col, col1, col2, ...)
SELECT S.key_col, S.col1, S.col2, ...
FROM DB2.dbo.SourceTable AS S
LEFT JOIN DB1.dbo.TargetTable AS T
ON S.key_col = T.key_col
WHERE T.key_col IS NULL

Obviously this won't be useful if Key_col is an IDENTITY column. Use the
natural key of your table(s).

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
Thanks, it works great. Now, I just have to do this for about 20 more
tables. :)

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: puppet_sock | last post by:
I guess this is an architecture question. The question is: If I've got two (or more) Oracle databases, when does it make sense to integrate them into a single database, and when should they be...
2
by: Martin McNally | last post by:
My company maintains 40 replicated Sybase databases using a merge replication approach. It's difficult to update all 40 databases when a structure change occurs. Structure changes are minor,...
1
by: Christian Büttner | last post by:
hi, i have a sqlserver CE and a sqlserver database. The tables are exactly the same on both databases. the sqlserver CE database Content will be synchronized with the sqlserver database with...
15
by: sparks | last post by:
They are wanting to use word to print out some cards 4 to a page preformatted stuff from an access database. the problem with this is they don't want to do the same card twice. How can setup a...
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
4
by: Shaldaman | last post by:
Hi, We're running Office 2000 at our organization. We've been using an Access database that is shared on the network; we have forms in the database in which when we click on a button, data is...
2
by: JK | last post by:
I saw Danny Lesandrini's article on Database Journal (http://www.databasejournal.com/features/msaccess/article.php/2236471) on how to merge tables from identical databases. This is exactly what...
1
by: ammie | last post by:
I have two databases with identical tables structures. I need to merge the data in both databases without implementing merge replication. Can someone tell me what script to run that will compare...
3
by: HarryTheB | last post by:
Hi, I am using the following code in Access 2003 to merge data from a query to a table in a Word document: Private Sub BtnMerge_Click() Dim db As DAO.Database Dim objWord As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.