级联软删除 [英] Cascading Soft Delete

查看:98
本文介绍了级联软删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL一直都有一个很棒的功能:级联删除.您需要预先计划,何时需要删除某些内容,BAM!无需担心所有这些从属记录.

SQL has always had a great feature: cascading deletes. You plan it in advance and when it's time to delete something, BAM! No need to worry about all those dependent records.

但是,如今实际上删除任何东西几乎是禁忌.您将其标记为已删除并停止显示.不幸的是,当有相关记录时,我无法找到一个可靠的解决方案.我总是手动编写复杂的软删除代码.

However, nowadays it's almost taboo to actually DELETE anything. You flag it as deleted and stop showing it. Unfortunately, I haven't been able to find a solid solution to doing this when there are dependent records. I've always manually coded the complicated web of soft deletes.

有没有一种更好的解决方案我完全错过了?

Is there a better solution out there that I have completely missed?

推荐答案

我讨厌这么说,但是触发器是专门为这种事情设计的.

I hate to say it but triggers are designed specifically for this kind of thing.

(讨厌的部分是因为好的触发器很难编写,而且当然不能调试)

(The hate part is because good triggers are very hard to write and , of course , cannot be debugged)

这篇关于级联软删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆