如何在插入或更新时同时更新表中的FK。 [英] How do I update FK in a table on insert or update simultaneously.
本文介绍了如何在插入或更新时同时更新表中的FK。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我构建了一个包含10个表的数据库,我希望其他表中的FK是在插入,更新,删除数据时自动更新的。使用TRIGGER或ON CASCADE。如何实现填充一个表的一行但同时填写FK的同时?
I have constructed a DB with 10 tables on it and I want the PK which are FK in other tables to auto update upon inserting, updating, deleting data into them. do I use 'TRIGGER' or 'ON CASCADE'. How does one achieve filling in one line of one table but at the same time the FK's fill in same time?
推荐答案
我建议使用UPDATE CASCADE和DELETE CASCADE来维护参照完整性。以下是有关该主题的有用资源:
https://www.mssqltips.com/sqlservertip/2743/using-delete-cascade-option-for-foreign-keys/ [ ^ ]
I recommend using UPDATE CASCADE and DELETE CASCADE to maintain referential integrity. Here is a helpful resource on the topic:
https://www.mssqltips.com/sqlservertip/2743/using-delete-cascade-option-for-foreign-keys/[^]
这篇关于如何在插入或更新时同时更新表中的FK。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文