简体   繁体   English

根据其父子层次选择模式中的所有表

[英]Select all tables in schema based on their parent-child hierarchy

My requirement is to delete data from couple of table selected dynamically based on search condition. 我的要求是从基于搜索条件动态选择的几张表中删除数据。

So my cursor should fetch tables in their parent-child hierarchy so that it will not give exception 'CHILD RECORD FOUND' while deleting records. 因此,我的游标应获取其父子层次结构中的表,以便在删除记录时不会出现异常“ CHILD RECORD FOUND”。

lets take exable 让我们接受

Table A is child of Table B 表A是表B的子级

Table B is child of Table C 表B是表C的子级

Table D is child of table G 表D是表G的子级

So it should delete in this sequence. 因此,应按此顺序删除。

A then 然后
B or D then 然后B或D
D or G D或G

If you use cascading foreign keys, you don't have to worry about table order. 如果您使用级联外键,则不必担心表的顺序。 Just delete from the top of the hierarchy (table G in in your example) and then all dependent rows in the descendent tables will be deleted atomically. 只需从层次结构的顶部删除(在您的示例中为表G),然后后代表中的所有相关行将被原子删除。

Read more about Cascading Referential Integrity Constraints . 阅读有关级联参照完整性约束的更多信息。


Re your comment: 发表您的评论:

Also it should be generic enough to handle delete even if delete cascade is not there and we do not have knowledge of dependencies. 而且,即使没有删除级联并且我们没有依赖关系,它也应该足够通用以处理删除。

See these questions for tips on discovering constraints in Oracle: 有关在Oracle中发现约束的提示,请参见以下问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM