实现软删除的最佳方法是什么? [英] What is the best way to implement soft deletion?

查看:35
本文介绍了实现软删除的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在做一个项目,我们必须对大多数用户(用户角色)实施软删除.我们决定在数据库中的每个表上添加一个 is_deleted='0' 字段,并在特定用户角色点击特定记录上的删除按钮时将其设置为 '1'.

Working on a project at the moment and we have to implement soft deletion for the majority of users (user roles). We decided to add an is_deleted='0' field on each table in the database and set it to '1' if particular user roles hit a delete button on a specific record.

为了现在的未来维护,每个 SELECT 查询都需要确保它们不包含记录 where is_deleted='1'.

For future maintenance now, each SELECT query will need to ensure they do not include records where is_deleted='1'.

是否有更好的实现软删除的解决方案?

Is there a better solution for implementing soft deletion?

更新:我还应该注意到,我们有一个审计数据库,用于跟踪应用程序数据库中所有表/字段的更改(字段、旧值、新值、时间、用户、IP).

Update: I should also note that we have an Audit database that tracks changes (field, old value, new value, time, user, ip) to all tables/fields within the Application database.

推荐答案

您可以针对包含 WHERE IS_DELETED='0' 子句的视图执行所有查询.

You could perform all of your queries against a view that contains the WHERE IS_DELETED='0' clause.

这篇关于实现软删除的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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