级联删除和更新的优点和缺点是什么?
也许这是一个天真的问题......但我认为我们应该始终进行级联删除和更新。但我想知道它是否存在问题以及我们什么时候不应该这样做?我现在真的想不出一种情况,您不想进行级联删除,但我确信有一个......但是更新应该总是进行吗?
那么有人可以列出级联删除和更新的优点和缺点吗?谢谢。
Maybe this is sort of a naive question...but I think that we should always have cascading deletes and updates. But I wanted to know are there problems with it and when should we should not do it? I really can't think of a case right now where you would not want to do an cascade delete but I am sure there is one...but what about updates should they be done always?
So can anyone please list out the pros and cons of cascading deletes and updates ? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
优点:
缺点
Pros:
Cons
这取决于表中包含的实体:如果没有主键一侧就不能存在外键一侧,则级联删除是有意义的。
例如:如果发票被删除,发票行项目就没有任何权利继续存在。
但是,如果您有一个外键用于员工与其老板之间的关系“为”工作,那么如果老板离开公司,您是否想要删除该员工?
另外:一个技术问题是,如果依赖表条目发生变化,一些 ORM(对象关系映射)工具会感到困惑,而它们对此不负责。
This depends on the entities that are contained in the tables: if the side of the foreign key cannot exist without the side of the primary key, it makes sense to have cascaded delete.
E. g.: An invoice line item does not have any right to survive if the invoice is deleted.
But if you have a foreign key used for the relationship "works for" for the relationship between an employee and his/her boss, would you want to delete the employee if the boss leaves the company?
In addition: a technical issue is that some ORM (object relational mapping) tools are confused if dependent table entries change without them being responsible for that.
优点:
缺点:
Pros:
Cons: