Tuesday, October 11, 2011

to find common column name in tables

Use data dictionary views.

select * from sys.all_tab_columns where owner like 'owner_name ' and column_name like 'column_name' ;


e.g.

select a.column_name,b.table_name from
(select column_name, count(*) from sys.all_tab_columns
group by column_name
having count(*)>1) a, sys.all_tab_columns b
where
a.column_name=b.column_name
order by a.column_name

Essentially you get the column names from the all_tab_columns where which
are appears in more than 1 table, then you join the table names to them
again from the same dictionary view.
I hope, this helps.

No comments: