select table_name,max(level) sac
from
(
select a.table_name,
a.constraint_name pkey_constraint,
b.constraint_name fkey_constraint,
b.r_constraint_name
from user_constraints a, user_constraints b
where a.table_name = b.table_name
and a.constraint_type = 'P'
and b.constraint_type = 'R'
and a.table_name not in ('COMPANY','OPPORTUNITY_STATUS')
union all
select table_name, constraint_name, null, null
from user_constraints
where constraint_type = 'P'
and table_name not in ('COMPANY','OPPORTUNITY_STATUS')
union all
select table_name,null,null,r_constraint_name
from user_constraints
where constraint_type = 'R'
and table_name not in ('COMPANY','OPPORTUNITY_STATUS')
)
start with fkey_constraint is null
connect by prior pkey_constraint = r_constraint_name
group by table_name
order by 2

No comments:
Post a Comment