I work with very large Oracle enterprise databases all the time. Consistently, I find myself trying to sift through schemas in the database to find relationships between tables. When tables aren’t named appropriately and you have a lot of them, this can be a long and painful process if you do it manually.
Lucky for us, there is a convenient way to search for the tables you’re looking for based on column information.
In your SQL tool of choice take the following command:
select table_name from all_tab_columns where column_name = 'PICK_COLUMN';
If you’ve got DBA privileges, you can try this command instead:
select table_name from dba_tab_columns where column_name = 'PICK_COLUMN';
Now if you’re like me, you may not even know what the column you’re searching for is really named. One can only hope the name is similar, which is why you can use the like
clause and throw in a few wild cards.
When describing the structure of the all_tab_columns view, you get the following:
Column Name | Null Allowed | Data Type |
---|---|---|
owner | not null | varchar2(30) |
table_name | not null | varchar2(30) |
column_name | not null | varchar2(30) |
data_type | null | varchar2(106) |
data_type_mod | null | varchar2(3) |
data_type_owner | null | varchar(120) |
data_length | not null | number |
data_precision | null | number |
data_scale | null | number |
nullable | null | varchar2(1) |
column_id | null | number |
default_length | null | number |
data_default | null | long() |
num_distinct | null | number |
low_value | null | raw(32) |
high_value | null | raw(32) |
density | null | number |
num_nulls | null | number |
num_buckets | null | number |
last_analyzed | null | date |
sample_size | null | number |
character_set_name | null | varchar2(44) |
char_col_decl_length | null | number |
global_stats | null | varchar2(3) |
user_stats | null | varchar2(3) |
avg_col_len | null | number |
char_length | null | number |
char_used | null | varchar2(1) |
v80_fmt_imag | null | varchar2(3) |
data_upgraded | null | varchar2(3) |
histogram | null | varchar2(15) |
The column_name, table_name, and owner are the only fields I use, but you may find others of use. If you want to search for tables in a particular schema based on column information, you would set the owner to the name of your schema in the where
clause.