How to Implement Soft Deletion

What is the best way to implement soft deletion?

You could perform all of your queries against a view that contains the WHERE IS_DELETED='0' clause.

Implementing soft delete with minimal impact on performance and code

If the key is numeric, I handle a "soft-delete" by negating the key. (Of course, won't work for identity keys). You don't need to change your code at all, and can easily restore the record by multiplying by -1.

Just another approach to give some thought to... If the key is alphanumeric, you can do something similar by prepending a unique "marker" characters. Since deleted records will all begin with this marker, then will end up off by themselves in the index.



Related Topics



Leave a reply



Submit