Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare columns between two database in different schemas

Status
Not open for further replies.

mkey

Programmer
Oct 3, 2001
288
CA
Hi All,
Scenario:
Schema_one.table_one(id number, name varchar2(10))
Schema_two.table_one(name varchar2(10))
Schema_one.table_two(a number, b varchar2(5))

I need to check the number of columns for all the table that are the same in both schemas. So in this case Schema_two.table_one does not have id column and I want to output that. But I do not want to output the table_two.

My script look something like this:

SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM DBA_TAB_COLUMNS WHERE
OWNER = 'Schema_one'
UNION
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM DBA_TAB_COLUMNS WHERE
OWNER = 'Schema_two'
MINUS
(SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM DBA_TAB_COLUMNS WHERE OWNER = 'Schema_one'
INTERSECT
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM DBA_TAB_COLUMNS WHERE OWNER = 'Schema_two');

This query is returns table_one id and table_two a and b.
So how can I change my query to filter out for this?
Any thoughts will help.
Thank you for all your support.
mkey

 
Try this:
Code:
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE 
FROM DBA_TAB_COLUMNS D1 
WHERE OWNER = 'Schema_one'
AND EXISTS (
   SELECT TABLE_NAME
   FROM DBA_TABLES
   WHERE OWNER = 'Schema_two'
   AND TABLE_NAME = D1.TABLE_NAME)
UNION
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE 
FROM DBA_TAB_COLUMNS D2 
WHERE OWNER = 'Schema_two'
AND EXISTS (
   SELECT TABLE_NAME
   FROM DBA_TABLES
   WHERE OWNER = 'Schema_one'
   AND TABLE_NAME = D2.TABLE_NAME)
MINUS
(SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE 
FROM DBA_TAB_COLUMNS 
WHERE OWNER = 'Schema_one'
INTERSECT 
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE 
FROM DBA_TAB_COLUMNS 
WHERE OWNER = 'Schema_two');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top