Bar*_*arn 5 oracle partitioning
我正在为我们的 Oracle 数据库编写一个通用的 drop-all-objects 脚本。它drop table TABLE_NAME cascade constraints purge
通过循环遍历所有表,以及其他对象类型,生成行user_objects
。
问题是,表它们是有依赖于他们引用分区表不能以这种方式被丢弃:ORA-14656: cannot drop the parent of a reference-partitioned table
。
如何从数据字典中检测哪些表是参考分区表的父表,以便我可以在第一个循环中跳过它们,然后将它们放入第二个循环中?
要获得至少有一个引用分区子表的分区表的名单[dba][all][user]_part_tables
和[dba][all][user]_constrains
数据字典视图,根据授予的权限,可以查询:
create table tb_part_parent(
col number primary key,
col2 number
)
partition by range (col2) (
partition part_1 values less than (100),
partition part_2 values less than (300),
partition part_3 values less than (500)
)
create table tb_part_child(
col number not null,
col2 number,
constraint fk_parent_1 foreign key(col) references tb_part_parent(col)
)partition by reference (fk_parent_1)
Run Code Online (Sandbox Code Playgroud)
查询:
select t.table_name
from user_constraints t
where t.constraint_name in ( select w.r_constraint_name
from user_constraints w
join user_part_tables q
on (q.table_name = w.table_name and
q.ref_ptn_constraint_name = w.constraint_name)
)
Run Code Online (Sandbox Code Playgroud)
结果:
TABLE_NAME
-----------------
TB_PART_PARENT
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3715 次 |
最近记录: |