background

While studying MVC recently, I came across the word “soft delete” and took a look at it.

What is a “soft delete”?

Soft delete is also called logical delete or tag delete. Unlike delete, the record is not actually deleted from the database. Instead, a field such as IsDelete is set to mark the deletion status.

Why is there “soft delete”?

In fact, in practice, many times we say “delete” is not really “delete”, for example;

1. Shopping cart orders are not deleted, but "cancelled"; 2. Employees are not deleted, they are "fired" (or retired). 3. An employee's position is not deleted, it is "filled" (or a job application is withdrawn)Copy the code

So, in those cases, we can’t actually delete the record, so “soft delete” comes into being.

Of course, we would prefer to use a status word instead: IsDelete, as we have seen: valid, disabled, deprecated, and so on.

Soft deletion VS hard deletion

Although soft delete is better, it can ensure the integrity of data, but does not mean that we use soft delete at all times. Hard deletion is used when we are sure that some data is no longer needed. For example, the verification code, such data after deletion is not necessary to save.

conclusion

We should, according to the actual situation, reasonable use of soft delete and hard delete.