Search code examples
sqlsoft-delete

Cascading Soft Delete


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?


Solution

  • 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)