数据库:删除或不删除记录 [英] Database: To delete or not to delete records

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

问题描述

我不认为我是唯一想知道这个的人。你通常对数据库行为进行什么练习?你更喜欢从数据库中物理删除记录吗?

I don't think I am the only person wondering about this. What do you usually practice about database behavior? Do you prefer to delete a record from the database physically? Or is it better to just flag the record with a "deleted" flag or a boolean column to denote the record is active or inactive?

推荐答案

或者是最好使用已删除标志或布尔列标记记录以表示记录处于活动或非活动状态

这绝对取决于数据库的实际内容。如果你使用它来存储会话信息,那么当会话过期(或关闭)时,立即擦除它,你不想要那个垃圾。因为它不能真正再用于任何实际目的。

It definitely depends on the actual content of your database. If you're using it to store session information, then by all means wipe it immediately when the session expires (or is closed), you don't want that garbage lying around. As it cannot really be used again for any practical purposes.

基本上,你需要问自己,我可能需要恢复这些信息吗?像删除的问题SO,他们应该肯定只是标记为删除,因为我们正在允许取消删除。

Basically, what you need to ask yourself, might I need to restore this information? Like deleted questions on SO, they should definitely just be marked 'deleted', as we're actively allowing an undelete. We also have the option to display it to select users as well, without much extra work.

如果您没有积极寻求完全恢复数据,但是您可以选择 d仍然喜欢保持它的监测(或类似)的目的。我建议你(尽可能地)解决一个聚合方案,并推送到另一个表。这将保持您的主表清理删除的数据,以及保持您的辅助表优化监测目的(或任何你想到的)。

If you're not actively seeking to fully restore the data, but you'd still like to keep it around for monitoring (or similar) purposes. I would suggest that you figure out (to the extent possible of course) an aggregation scheme, and shove that off to another table. This will keep your primary table clean of 'deleted' data, as well as keep your secondary table optimized for monitoring purposes (or whatever you had in mind).

数据,请参阅: http:// talentedmonkeys。 wordpress.com/2010/05/15/temporal-data-in-a-relational-database/

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

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