删除数据库记录unpermenantley(软删除) [英] Deleting database records unpermenantley (soft-delete)

查看:169
本文介绍了删除数据库记录unpermenantley(软删除)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的故事

我会写一些code在我的应用程序来管理删除的项目,但我要删除柔和他们,所以我可以回报他们回来时,我需要的。我有一个层次在我的应用程序的逻辑,尊重,当涉及到隐藏或删除项目。

我在逻辑上把我的项目在三个容器到全国,市,区和品牌。
每个项目应该属于一个国家,一个城市,一个地区,一个品牌。
现在,如果我删除了一个国家,它应该删除的市,区,品牌和物品属于特定国家。如果我删除了城市,也应该删除其下的整个东西(区,品牌等)


的注

当我删除一个国家和删除相关的品牌,我应该照顾一个品牌可能有一个以上的国家项目。


问题

你建议


  1. 标志的项目(无论是国家,城市,项目等)为删除,这将需要大量的code来检查,每次当任何项目从数据库加载,如果它删除或不,还有一些额外的字段来标记它是否属于城市被删除,它属于该国将被删除等。


  2. 将每个被删除的东西给特定的表(DeletedCountries,删除城市,等等)
    并保存它与如此关联的项目的的ID,我可以将它们插入回来以后到它的原始表。当然这将节省我的应用程序的所有code将管理检查所有已删除的邮件,并确保所有层次将被删除。


  3. 也许你有一个更好的方法/咨询/对实现这样的事情的想法!



解决方案

有关参数的缘故,溶液#2(移动删除的项目,以自己的表)一个优点是,如果你有很多很多的记录,你就不必对于其已删除状态担心索引记录。

随着中说,如果我从表中要移动数据表(通过删除后插入)我会确保做到这一点在1交易。

The Story

I'm going to write up some code to manage the deleted items in my application, but I'm going to soft delete them so I could return them back when I need. I have a hierarchy to respect in my application's logic when it comes to hiding or deleting items.

I logically place my items in three containers to the country, city, district and brand. Each item should belong to a country, a city, a district and a brand. Now, if I deleted a country it should delete the cities, districts, brands, and items that belongs to the given country. and if I deleted the city it should also delete the whole stuff under it (districts, brands, etc)


A Note

When I delete a country and delete the associated brands, I should take care that a brand might have items in more than one country.


The Question

Do you suggest to

  1. Flag the items (whether it's country, city, item, etc) as deleted and this will require a lot of code to check every time when any item is loaded from the database, if it's deleted or not and also some extra fields to mark if the city it belongs to is deleted, and the country it belongs to is deleted and so on.

  2. Move the deleted stuff each to a specific table (DeletedCountries, Deleted Cities, etc) and save the the IDs of the items it was associated with so I could insert them back later to it's original table. and of course this will save my application all the code that will manage to check all the deleted items and make sure all the hierarchy is deleted.

  3. Maybe you have a better approach/advice/idea about achieving such a thing!

解决方案

For argument's sake, one advantage of solution #2 (moving deleted items to their own tables) is if you have lots and lots of records, you would not have to worry about indexing records in respect to their "deleted" state.

With that said, if I were going to "move" data from table to table (via delete followed by insert) I would make sure to do it in 1 transaction.

这篇关于删除数据库记录unpermenantley(软删除)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆