Relational Database: DELETE versus "Mark for Deletion"

Viewed 2759

Recently, I stumbled about the following problem: Given is a simple data model with "Books" and "Authors". Each "Book" has a reference to an "Author". Persistence is achieved with a relational database. Besides adding books and authors, it is also possible to delete them. Usually, if I want to delete an Author, i would perform a SQL DELETE operation and remove the corresponding row. However, I have seen in other projects, people don't call DELETE. Instead, they add some kind of active/deleted flag and mark the corresponding row as "deleted".

My questions are: Is this in general best practice? What are the advantages? My best guess is:

  • Setting a flag has a better performance than a DELETE operation
  • If you run out of space, it is still possible to run a cleanup service which looks for deleted object and removes the corresponding rows
  • Setting a delete flag is better for database consistency because a deletion of "Author" in the example above could destroy foreign keys in the corresponding "Book entries.

Anyway, these are just guesses. Does someone know the answer?

1 Answers
Related