首页 > 解决方案 > 外键列更新

问题描述

有两个表:

tblInvestType(Parent table) and
tblInvestTypeComp(Child table)

该列tblInvestTypeComp.type_code是一个外键引用tblInvestType.type_code

如何创建触发器,以便每当父表的 ( tblInvestType)type_code列的值有任何更新时,都会反映到子表的 ( tblInvestTypeComp)type_code列?

注意:所有这些都在 Oracle 中。

标签: oracledatabase-triggerreferential-integrity

解决方案


这是糟糕的设计。主键应该是不可变的。但是鉴于您有一个要求,这里有一个解决方案:

Create trigger upd_trg after update on tblInvestType
 for each row
Begin
    Update tblInvestTypeComp
    Set type_code =:new.type_code
    Where type_code =:old.type_code;
End;

推荐阅读