I will not try to be "politically correct about it". If you are advocating soft-delete then you need to go for a brain checkup.
1)
First, what exactly are you achieving by not deleting the rows in table? Just the fact that sometime in future you can access those rows, right? So why not just create an archive Table and move the rows there? what is wrong with that?
2)
With soft-delete you are creating unnecessary query on is_active or query on some time-stamp column. That is just waste when you would be writing simpler queries. Yes, it will work with a view but are views not an extra appendage? Every view is an extra SQL, extra performance cost, down under in any commercial RDBMS everything is a table only. There is nothing magical about views apart from the fact that you do not know how to write queries on top of tables.
3) Yes, it will work with a View or MV. But then I have seen queries in production doing FTS and everything still works! The wonders of modern hardware and solid software. But then that does not make it right either. So by same logic, just because it works does not mean it is RIGHT
4) The complexities of soft delete never ever stops at a simple select.
A) Suppose you had a UNIQUE constraint. Now you soft-delete a row but the column with UNIQUE constraint is still there. When you want to add the same data back in, you cannot do that without additional "tricks".
B) You may have associations going from Table A to Table B and when you soft delete something from Table A, you need to ensure that independent queries on Table B take care of that fact. Suppose a typical detail page was working on some detail_id.
Now a master_id is soft deleted but you still have permalinks with detail_id of that master_id everywhere. When you do hard delete on master_id, those details simply do not exist. Now with soft delete they still exists and they have to be aware of the fact that their master_id is in soft-delete mode.
it will not stop at a simple Table_A.is_active = 0 or 1 stage.
5) Doing hard deletes is simple and right.
A) No one has to add anything extra or worried about anything anywhere.
- Your application logic is simpler
- Your database is smaller
- Your queries are faster
Just archive the data + related pieces and you should be good.
IsDeleted
attribute on a table. The result was frequent reoccurring bugs. The problem should be obvious: every query that a regular user wanted to run against the table involvednon-deleted
data, meaning 99.9% of queries involving this table had to add...AND IsDeleted = 'N'
to itsWHERE
clause. Naturally, it was often omitted: either the coder forgot to add it or weren't aware they had to add it in the first place. Of course, there was no requirement for this in the original spec, the coder was using their initiative...VIEW
. IfIsDeleted
is added afterwards, it should be even possible to rename the original table, saymytable
tomytable_all
and then name the view asmytable
and add another view calledmytable_deleted
. That way no references to the table need to be changed.