Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2008, 10:04 AM
Registered User
 
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare 2 tables in 2 different DBs

Hello. I have to compare the values from 1 table from one database and 1 table from another database in the same server. Can anyone suggest how to do this?

I do not want to use any third party tools. I need to do this programmatically - only with sql server and C# and if there is a possibility to use only sql server.

 
Old February 15th, 2008, 10:17 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Just fully qualify the tables.

Something like this:

SELECT t1.*, t2.* from [Database1].[dbo].[table] t1
JOIN [Database2].[dbo].[table] t2 on t1.column = t2.column

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 15th, 2008, 10:36 AM
Registered User
 
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot. That was very helpfull.

 
Old March 7th, 2008, 03:12 AM
Authorized User
 
Join Date: Jun 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just fully qualify the tables.

Something like this:

SELECT t1.*, t2.* from [Database1].[dbo].[table] t1
JOIN [Database2].[dbo].[table] t2 on t1.column = t2.column


 
Old March 7th, 2008, 08:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

It looks like you have solved the problem. If not and your tables are really big and you need to find only the different rows you can use scripts which do that.
It is completely SQL,
http://www.sqlservercentral.com/scri...laneous/30221/


G.R.Preethiviraj Kulasingham





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare two fields from different tables pallone SQL Server 2000 10 March 23rd, 2007 05:14 PM
Compare records between two tables jaaboston Access VBA 1 December 21st, 2006 05:35 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
how to compare tables data ramanadyv SQL Language 0 April 10th, 2006 04:38 AM
Compare 2 tables.... Seb_soum Classic ASP Databases 2 June 4th, 2004 05:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.