Skip to content

Instantly share code, notes, and snippets.

@uilian
Created September 16, 2014 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uilian/08aadb62f6ab42030cf1 to your computer and use it in GitHub Desktop.
Save uilian/08aadb62f6ab42030cf1 to your computer and use it in GitHub Desktop.
Identify table references
select
distinct *
from
(
select
upper(:table_name) tabela,
'is refereced by' behaviour,
b.table_name
from
all_constraints a,
all_tables b
where
a.constraint_type = 'R' and
a.table_name = b.table_name and
b.owner = :owner and
a.r_constraint_name in
(select x.constraint_name from all_constraints x, all_tables y
where x.constraint_type in ('P', 'U') and x.table_name = UPPER(:table_name) and x.table_name = y.table_name and y.owner = :owner)
union all
select
upper(:table_name) tabela,
'has references to' behavior,
a.table_name
from
all_constraints a,
all_tables b
where
a.table_name = b.table_name and
b.owner = :owner and
constraint_name in
(select r_constraint_name from all_constraints x, all_tables y where y.owner = :owner and x.table_name = UPPER(:table_name) and y.table_name = x.table_name)
)
order by 1,2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment