如何为数据库应用程序制作回收站?

发布于 2024-08-03 23:23:36 字数 470 浏览 9 评论 0原文

我有数据库应用程序,我想允许用户从数据库中恢复已删除的记录,就像在Windows中我们有文件回收站我想做同样的事情,但对于数据库记录,假设我有很多相关的表有很多字段。

编辑:

假设我有以下结构:

报告表

  • RepName 主键
  • ReportData

用户表

  • ID 主键
  • 名称

UserReports 表

  • RepName 主键
  • UserID 现在主键
  • IsDeleted

如果我将 isdeleted 字段放入 UserReports 表中,如果标记为已删除,用户将无法再次添加相同的记录,因为该记录已经存在,这会造成重复。

I have database application, I want to allow the user to restore the deleted records from the database, like in windows we have Recycle bin for files I want to do the same thing but for database records, Assume that I have a lot of related tables that have a lot of fields.

Edit:

let's say that I have the following structures:

Reports table

  • RepName primary key
  • ReportData

Users table

  • ID primary key
  • Name

UserReports table

  • RepName primary key
  • UserID primary key
  • IsDeleted

now if I put isdeleted field in UserReports table, the user can't add same record again if it marked as deleted, because the record is already and this will make duplication.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给妤﹃绝世温柔 2024-08-10 23:23:36

注意:我总是使用代理主键。

添加时间戳“deleted_at”列。当用户删除条目时,将当前时间放在那里。让这个关键部分成为你的约束。

在每个查询中,请记住仅搜索deleted_at 字段中包含 null 的记录。

某些框架(例如 ActiveRecord)使其变得微不足道。

Note: I always use surrogate primary key.

Add a timestamp 'deleted_at' column. When user deletes entry put there current time. Make this key part of your constrain.

In every query remember to search only for records that have null in deleted_at field.

Some frameworks (like ActiveRecord) make it trivial to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文