oracle - 外键列更新
问题描述
有两个表:
tblInvestType(Parent table) and
tblInvestTypeComp(Child table)
该列tblInvestTypeComp.type_code
是一个外键引用tblInvestType.type_code
。
如何创建触发器,以便每当父表的 ( tblInvestType
)type_code
列的值有任何更新时,都会反映到子表的 ( tblInvestTypeComp
)type_code
列?
注意:所有这些都在 Oracle 中。
解决方案
这是糟糕的设计。主键应该是不可变的。但是鉴于您有一个要求,这里有一个解决方案:
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;
推荐阅读
- java - java - 在Java jsp中输入键事件时如何隐藏警报div
- r - 将列表传递给函数参数?
- r - 如何为 glmer 添加 CI 误差线并在 plot_model 中编辑截距图?
- java - Java - netbeans - notepadGUI 的撤消/重做代码
- python - 迭代目录下的文件时出现 FileNotFoundError
- javascript - REACT APP 无法访问谷歌云运行环境变量
- php - 获取 woocommerce 产品属性 url 以在产品页面上显示为图像
- visual-c++ - 在 Windows C++ 应用程序中获取显卡名称和信息的最佳方式是什么?
- privacy - 某些网站上的“使用 Facebook 注册”如何包含我的姓名甚至头像?
- python - 将数据集转换为要绘制的库列表