[英]How to design database request/approval tables?
I have the following kind of request tables: 我有以下几种请求表:
oversea_study_request
course_request
leave_request
in these request functions, approving officer can post multiple remarks and also approve or reject the request. 在这些请求功能中,审批人员可以发表多条评论,也可以批准或拒绝该请求。 The system must be able to capture the history of the actions taken. 系统必须能够捕获所采取动作的历史记录。
What is the best way to design it? 最好的设计方法是什么?
Can someone advise on the pros and cons of each approach? 有人可以就每种方法的利弊提供建议吗?
Similar to the fields organisation question here: How to better organise database to account for changing status in users ; 类似于此处的字段组织问题: 如何更好地组织数据库以解决用户的更改状态 ; and my answer there : 还有我的回答 :
If the all the requests have the same fields , field types and info, including mandatory ( NOT NULL
) and optional, etc. then it's better to put all the requests into one requests
table . 如果所有请求都具有相同的字段 ,字段类型和信息,包括必需的( NOT NULL
)和可选的等,那么最好将所有请求放入一个requests
表中 。 Designate one field to be request_type
, with an int for efficiency and SQL convenience, or an ENUM type . 将一个字段指定为request_type
,为效率和SQL方便性使用int或ENUM type 。 Example: 例:
overseas study = 1
course = 2
leave = 3
Similarly, do that for the approvals
table also...if the process is the same for each type then store those together. 同样,对approvals
表也要这样做...如果每种类型的处理过程相同,则将它们存储在一起。 Store the request id ( requests.id
). 存储请求ID( requests.id
)。 Since you have multiple approval-comments and approval+rejection possible, store these in approvals.action
and approvals.action_date
. 由于您可能有多个批准注释和批准+拒绝,因此将它们存储在approvals.action
和approvals.action_date
。 If "actions" are independent of "approve/reject" - that is, if you can post a comment without approving/rejecting OR if you can approve/reject without a comment - then store the actions
and comments
separately, and include the request.id
. 如果“操作”与“批准/拒绝”无关-也就是说,如果您可以在不批准/拒绝的情况下发布评论,或者在您可以批准/拒绝而没有评论的情况下-然后分别存储actions
和comments
,并包含request.id
。
So you have: 所以你有了:
Table1: requests
id INT
request_type INT (or ENUM)
request_date DATETIME
...
Table2: approvals (or 'actions', to be general)
id
request_id # (refers to requests.id above)
action_type # (approve or reject)
action_date
comment
If comments and approvals are NOT necessarily together, then: 如果意见和批准不一定在一起,那么:
Table2: actions
id, request_id, action_type, action_date
Table3: comments
id, request_id, comment, comment_date
And of course, add the user_id, username, etc. tables/fields. 当然,还要添加user_id,用户名等表/字段。 (The id
in each table is it's own Primary Key) (每个表中的id
是它自己的主键)
Each request + actions + comments can be found with a SELECT
and LEFT JOIN
s 每个请求+动作+注释都可以通过SELECT
和LEFT JOIN
找到
Btw, it's "overseas" study, not "oversea" study - it's not a course in an airplane ;-) 顺便说一句,这是“海外”学习,而不是“海外”学习-这不是飞机上的课程 ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.