Sometimes you want to mark a DB table record as deleted instead of deleting it permanently, right?
How do you do that?
So far I’ve been using a boolean “deleted” field but I’m not sure if it’s a good apprach.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s about it – a boolean field to indicate that the record is deleted. The few times I used that, I called that field
IsDeleted.This is often referred to as Logical Delete.
It’s up to you to respect that field in your reports – which means excluding all the records with
IsDeleted = true. Those queries can get a little complicated if you have a lot of tables and relations.Also, you may encounter some problems if you have unique constraints on a table. For example, if in a user table a user has
IsDeleted = trueand the email column is unique, i would not be possible to add a new user with same email address.There are some ORM which take those fields into consideration – for example, SubSonic 2.2 will not delete a record if there is a column named ‘Deleted’ or ‘IsDeleted’, instead it will set this field to true.
Some related resources:
As an alternative to this you could add auditing tables.