Wednesday, March 7, 2012

How to compare 2 tables ot different DBs in Oracle style

In Oracle this is done this way :
SQL>
1 select ID, NAME from TABLENAME
2* minus select ID,NAME from TABLENAME@.DATABASE2
SQL>

Any ideas ?Yeah...minus is a way to do a non existance checj=k...or a left outer join where the right table key is null...

I don't know what your talking about with @.DATABASE2|||Originally posted by Brett Kaiser
I don't know what your talking about with @.DATABASE2 That's Oracle speak for DATABASE2..TABLENAME in SQL-92.

-PatP|||See...my Oracle naivite' is showing...

Never dealt with more than 1 db in Oracle...|||select ID, NAME from TABLENAME
minus select ID,NAME from TABLENAME@.DATABASE2

This statement compares table TABLENAME in current database and DATABASE2 and shows the lines that are missing in the current database.

If it returns

1 | Test1
2 | Test2

this meanse that these 2 lines exists in TABLENAME in current DB, and doest not exists in TABLENAME in DATABASE2.

In SQL Server it should be something like this :

SELECT ID, NAME FROM TABLENAME
MINUS
SELECT ID,NAME FROM DATABASE2..TABLENAME

but we don't have MINUS in T-SQL|||Might I suggest using a FULL OUTER JOIN to see what was added or deleted, then a compare of the column values to see what keys have different values associated with them?

-PatP|||FYI, http://www.sql-server-performance.com/vg_database_comparison_sp.asp

Originally posted by The-Saint
In Oracle this is done this way :

SQL>
1 select ID, NAME from TABLENAME
2* minus select ID,NAME from TABLENAME@.DATABASE2
SQL>

Any ideas ?

No comments:

Post a Comment