omer schleifer
omer schleifer

Reputation: 3935

Logical delete from DB

I have a complex schema with many entitites and relations.I want to define a logical delete operation which can be undone. I've considered adding 'isDeleted' flag to every table, but it seems bug-proned to me. I've also considered adding an archive schema which is similar to the original schema, and on every delete operation to move the data there.That seems to require a lot of code to write for the "delete" and "undelete" operations (espacially since I want to emulate on delete casade for the logical delte).

Finally, I'm not sure where to handle the events of logical delete I'm using EF so I can do it in code, or maybe I can use the delete trigger in he DB.

I would appreiciate any recomendations on how to implement the logical delete in an elegant way. Thanks.

Upvotes: 1

Views: 246

Answers (2)

Robert Co
Robert Co

Reputation: 1715

Since this is an OLTP database, I don't have issue using the IsDeleted flag. If you are worried about performance, I will continue using the IsDeleted flag and move it to archive through a batch process, not online.

One thing that I always keep in mind to avoid over-architecting something - It's not a problem unless it's a problem.

Upvotes: 0

Alon Catz
Alon Catz

Reputation: 2530

Every company I worked for has always used a logical delete flag and managed it through code. Adding an archive schema is a huge overhead and IMO its added elegancy (both coding and performance wise) doesn't worth the extra effort.

Upvotes: 4

Related Questions