Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Cross databases

Author  Topic 

jfm
Posting Yak Master

145 Posts

Posted - 2013-03-01 : 07:06:39
Hi there guys,

I have DB1 and DB2 (2 different Databases)

I need to double-check which info I'm missing in DB2. So I will need to cross the tables using Col1 and Col2 from each table.

Any idea?

thanks !!

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-01 : 07:32:55
Assuming they are on the same server, you could do any of the methods that people use to compare data in two tables - for example:
SELECT col1,col2 FROM DB1.dbo.TableA
EXCEPT
SELECT col1,col2 FROM DB2.dbo.TableA;

SELECT col1,col2 FROM DB2.dbo.TableA
EXCEPT
SELECT col1,col2 FROM DB1.dbo.TableA;
If you have a number of tables and columns, it is possible to use INFORMATION_SCHEMA.TABLES and INFORMATION_SCHEMA.COLUMNS to generate the list of tables and columns and construct the queries patterned after the above query.
Go to Top of Page
   

- Advertisement -