How can you tell which columns are unused in ALL_TAB_COLS?

thecoop picture thecoop · Jun 1, 2010 · Viewed 19.2k times · Source

When you query the ALL_TAB_COLS view on Oracle 9i, it lists columns marked as UNUSED as well as the 'active' table columns. There doesn't seem to be a field that explicitly says whether a column is UNUSED, or any view I can join to that lists the unused columns in a table. How can I easily find out which are the unused columns, so I can filter them out of ALL_TAB_COLS?

Answer

Tony Andrews picture Tony Andrews · Jun 1, 2010

Try using ALL_TAB_COLUMNS instead of ALL_TAB_COLS. In Oracle 11.2 I find that unused columns appear in ALL_TAB_COLS (though renamed) but not in ALL_TAB_COLUMNS.

I created a table like this:

create table t1 (c1 varchar2(30), c2 varchar2(30);

Then set c2 unused:

alter table t1 set unused column c2;

Then I see:

select column_name from all_tab_cols where owner='ME' and table_name='T1';

COLUMN_NAME
-----------
C1
SYS_C00002_10060107:25:40$

select column_name from all_tab_columns where owner='ME' and table_name='T1';

COLUMN_NAME
-----------
C1