• Delete Cascade if foreign keys exists with different delete rule.


    Suppose I have tables t1, t2, t3 and having the relation t1 -> t2 -> t3, where t1 is the
    root level parent and t3 is the child.

    Suppose, if there exists a relation between t1 and t2 with delete cascade,t2 and t3 with
    delete cascade and t1 and t3 with delete restrict.

    t1 --> t2 --> t3   (say delete cascade)
    t1 --> t3          (say delete restrict)

    Now, how does oracle determines, whether to delete the records from "t3" or not?

    If it chooses the path of t1 --> t2, t2 --> t3 then, it deletes the record and t1 --> t3
    may find no record to delete.
    On the other hand, if it chooses t1 -- t3, it fails with "child record found". Now my question is what strategy oracle uses to choose the delete path.

    It would appear we cascade the delete and then check:

    CREATE TABLE t1 (x INT PRIMARY KEY);

    CREATE TABLE t2 (y INT PRIMARY KEY, x    REFERENCES t1 ON DELETE CASCADE);

    CREATE TABLE t3 (y    REFERENCES t2 ON DELETE CASCADE, x    REFERENCES t1);

    INSERT INTO t1
      VALUES   (1);

    INSERT INTO t2
      VALUES   (2, 1);

    INSERT INTO t3
      VALUES   (2, 1);

    delete from t1;

    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    ES6中的reduce
    go.js 基本配置
    ES6(十二)类与对象
    ES6(十一)Proxy和Reflect
    ES6(十)map、set与数组和对象的比较
    ES6(九)set、map数据结构
    ES6(八)Symbol
    ES6(七)对象扩展
    hbase常识及habse适合什么场景
    Hbase与传统数据库的区别
  • 原文地址:https://www.cnblogs.com/tracy/p/1785252.html
Copyright © 2020-2023  润新知