As my client asked me to integrate soft delete on his web application. But I have never done this, please help me out.
Asked
Active
Viewed 159 times
-4
-
Welcome to Stack Overflow! This question is a little short on information. Can you share what you have tried, and what problems you have run into? Please read [how to ask questions on StackOverflow](http://stackoverflow.com/help/how-to-ask) – Jay Blanchard May 19 '15 at 12:23
-
https://www.google.com/search?q="soft+delete"&oq="soft+delete" – LittleBobbyTables - Au Revoir May 19 '15 at 12:23
-
1"Soft delete" means you don't actually delete the data. Instead, you include a flag on the data (perhaps a simple `IsDeleted` boolean value) which indicates if it should be visible to the application or not. So the application essentially ignores "soft-deleted" data, but anybody with access to the database (for audit purposes, perhaps), or another application for some other purpose, can still see it. – David May 19 '15 at 12:30
1 Answers
0
A soft delete is when you mark a record as deleted instead of deleting the record from the table.
To implement this you need another field in the table, for example named Deleted
. Use a bit/boolean field and set it to 0
or false
(depending on what database you use) when you create the record (and on existing records).
To delete a record you just change the value in that field. Example:
update
SomeTable
set
Deleted = 1
where
Id = @Id
Wherever you use that table you have to filter out the deleted records (unless they should actually be shown anyway). Example:
select
SomeField
from
SomeTable
where
Deleted = 0

Guffa
- 687,336
- 108
- 737
- 1,005