oracle 表列约束树结构

yqkkidmi  于 2022-11-28  发布在  Oracle
关注(0)|答案(1)|浏览(167)

我正在处理一个数据迁移项目,在为目标表生成数据的过程中,我需要确保每条记录都遵守表的约束。
我需要执行约束的树结构,该树结构将从我的目标表开始,到达需要包含可靠数据的最后一个表,以允许将数据成功加载到迁移目标表A中。
例如:

[Target Table A] Structure(
Column_1,
Column_2, -- constraint linked to [Foreign column on Table B]
COlumn_3, -- constraint linked to [Foreign column on Table C]
)

[Table B] Structure(
Column_11,
Column_12, -- constraint linked to [Foreign column on Table D]
COlumn_13,
)

[Table C] Structure(
Column_21,
Column_22,
COlumn_23,
)

[Table D] Structure(
Column_31,
Column_32,
COlumn_33,
)

Here i will need to perform an analyze on target Table A and the result must be like:

>Table A =>
          Contains 2 constraints on 2 tables that need data:
         -Table B =>
                    Constraint 1 contraint on 1 table:
                    -Table D
         -Table C
f3temu5u

f3temu5u1#

从这个开始

SELECT LEVEL, fk.table_name, fk.constraint_name, fk.r_constraint_name, pk.table_name as target_table
FROM user_constraints fk
    JOIN user_constraints pk ON fk.r_constraint_name = pk.constraint_name
START WITH fk.constraint_type = 'R'
CONNECT BY NOCYCLE PRIOR fk.r_constraint_name = fk.constraint_name
;

相关问题