I do not think I'm alone curious about this. Exactly what do you typically practice about database behavior? Do you'd rather remove an archive in the database physically? Or is it more beneficial to simply flag the record having a "erased" flag or perhaps a boolean column to denote the record is active or inactive?

It certainly is dependent around the actual content of the database. If you are utilizing it to keep session information, then go ahead and wipe it immediately once the session expires (or perhaps is closed), you wouldn't want that garbage laying around. Because it may not be utilized again for just about any practical reasons.

Essentially, what you ought to request yourself, might I have to restore these details? Like erased questions about SO, they ought to certainly you need to be marked 'deleted', as we are positively permitting an undelete. We have the choice to show it to choose customers too, with little work.

If you are not positively trying to fully restore the information, but you'd still prefer to ensure that it stays around for monitoring (or similar) reasons. I recommend that you simply determine (towards the extent possible obviously) an aggregation plan, and shove that on another table. This can keep the primary table clean of 'deleted' data, in addition to keep the secondary table enhanced for monitoring reasons (or anything you been on mind).

Like a compliment to any or all posts...

However, for those who intend to mark the record, its perfect for think about making a view, for active records. This could help you save from writing or failing to remember the flag inside your SQL query. You may think about a view for non-active records too, if you feel also serve an objective.

You will find also legalities in either case if private data is involved. It greatly is dependent on where you stand (or in which the database is), and exactly what the relation to use are.

In some instances people can request to become taken off the body, by which situation a tough remove is required (or at best cleaning all the private information).

I'd seek advice from your legal department before you decide to adopt a method in either case if private information is involved.

Pros of utilizing a remove flag:

  1. You will get the information back later if you want it,
  2. Remove operation (upgrading the flag) is most likely faster than really removing it

Cons of utilizing a remove flag:

  1. It's very simple to miss AND DeletedFlag = 'N' somewhere inside your SQL
  2. Reduced for that database to obtain the rows that you are looking at among all of the garbage
  3. Eventually, you'll most likely wish to really remove it anyway (presuming the body is effective. How about when that record is ten years old also it was "erased" 4 minutes after initially produced)
  4. It will make it impossible to utilize a natural key. You might have a number of erased rows using the natural key along with a real row attempting to use that same natural key.

I mark them as erased, and do not really remove. However every every now and then I sweep out all of the junk and archive it, therefore it does not kill performance.

I'm happy to have found this thread. I too wondered what individuals considered this problem. I've implemented the 'marked as deleted' for around fifteen years on many systems. Each time a user would call to express something was accidentally erased it had been certainly a great deal simpler to measure the level not-erased than recreate it or restore from the backup.

We're using postgresql and Ruby on rails it appears like we're able to do that in 1 of two ways, modify rails or add an ondelete trigger and does rather a pl/pgsql function to mark as erased. I'm leaning toward the second.

For performance hits, it will likely be interesting to determine the outcomes of EXPLAIN-Evaluate on large tables to couple of erased products in addition to many erased products.

In systems used with time I've discovered, new customers often do silly such things as remove things accidentally. Then when individuals are new ready they've all of the access privileges of the individual formerly for the reason that position except with zero experience. Accidentally removing something or being able to rapidly recover will get everybody to work rapidly.

But as someone stated, many times you need that one key back for whatever reason, at that time you should really remove it, then re-produce the records (on undelete it and customize the record).