有两个表:
tblInvestType(Parent table) and
tblInvestTypeComp(Child table)
列tblInvestTypeComp.type_code
是引用tblInvestType.type_code
的外键。
如何创建触发器,以便只要父表(tblInvestType
)type_code
列的值有任何更新,都会在子表({{1} })tblInvestTypeComp
列?
注意:所有这些都在Oracle中。
答案 0 :(得分:0)
您可以尝试以下
set constraint <constraint name> deferred;
update primary key ...
update foreign key column to match the updated primary key....
commit;
为此,必须将外键定义为可延迟
答案 1 :(得分:0)
这是糟糕的设计。主键应该是不变的。但是鉴于您的要求,这里有一个解决方案:
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;
答案 2 :(得分:0)
这是我得到的解决方案:
path