本文共 2418 字,大约阅读时间需要 8 分钟。
sqlplus -s < set pages 1000
set echo off set feedback off create table table_depency_rel as ( select p.table_name parent_table_name , p.owner p_owner, c.table_name child_table_name , c.owner c_owner from user_constraints p, user_constraints c where p.constraint_type IN ('P','U') AND c.constraint_type = 'R' AND p.constraint_name = c.r_constraint_name group by p.table_name,p.owner, c.table_name, c.owner ) ; --alter table table_depency_rel modify(p_owner null); alter table table_depency_rel modify(parent_table_name null); insert into table_depency_rel ( select null,null,parent_table_name,p_owner from table_depency_rel where parent_table_name not in (select child_table_name from table_depency_rel group by child_table_name)group by parent_table_name,p_owner ); set echo on set feedback on col table_node format a50 col level_code format a5 select decode(level,1,' connect by prior t.child_table_name =t.parent_table_name start with t.child_table_name in(select child_table_name from table_depency_rel where parent_table_name is null group by child_table_name) --order by parent_table_name desc;set feedback off
set echo off drop table table_depency_rel;EOF
exit 自己在反复模拟一些场景之后总结了如上的脚本。 我们来通过如下的方式运行脚本,查看system下的表依赖关系。 ksh showdepency.sh ----- -------------------------------------------------- ......
2- -----||DE_CRI_ALLOWED_OPS(2)
2- -----||DE_CRI_ITEMS(2)
3- --------||DE_CRI_CONNECTIONS(3)
3- --------||DE_CRI_POOL(3)
4- -----------||DE_CONDITIONS(4)
5- --------------||DE_DP_COMPONENTS(5)
6- -----------------||DE_CONTRIBUTE_LIST(6)
6- -----------------||DE_EXTRA_DPC_FIELDS(6)
6- -----------------||DE_TIERS(6)
7- --------------------||DE_STEPS(7)
可以很清晰的看到显示的层级关系,有1,2,3,4 其中1是根节点,2,3,4是依赖表,4依赖3,3依赖2,依此类推。运行脚本的时候是从第1级开始,逐次类推。 可以看到有些表的依赖都到第7级了,这些如果人工来一个一个审核,确实是很头疼的工作。来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23718752/viewspace-1382362/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23718752/viewspace-1382362/