如何为数据库应用程序制作回收站?
我有数据库应用程序,我想允许用户从数据库中恢复已删除的记录,就像在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:我总是使用代理主键。
添加时间戳“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.