基于 MySQL 触发器的审计日志记录与比较
在查看类似的问题时,例如:
我想采用这个进一步比较更新的数据,看看它是否确实已更新......我不确定这是否理想(性能方面)。
背景:
我们有一些由用户定期更新的数据。
当这些数据更新时,我想将他们提交的内容与已有的内容以及他们提交的内容进行比较,以确保发生了变化。
如果发生更改,请继续将审核条目写入中央审核历史记录表,概述已更改的字段。
想法/想法? 我尽了最大努力进行搜索,但运气不佳。 如果这个问题重复,我会很乐意删除它。
谢谢!
In looking at similar questions like:
Getting trigger to insert changed column values only in audit table
I would like to take this one step further and compare the updated data to see if it actually has been updated... I'm not sure if this is ideal (performance wise).
Background:
We have some data that is periodically updated by the user.
When this data is updated, I would like to compare what they submitted with what is already there and what they submitted, to make sure there has been a change.
If there has been a change, proceed to write an audit entry to the central audit history table outlining the fields changed.
Thoughts/ideas? I did my best to search but didn't have a lot of luck. I'll be happy to delete this question if it's a duplicate.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个
BEFORE UPDATE
触发器,在触发器中使用OLD
和NEW
别名来比较之前记录中可用的值使用您正在更新的值进行更新。 根据比较结果,您可以将条目写入审核表。You could write a
BEFORE UPDATE
trigger where you use theOLD
andNEW
aliases in your trigger to compare the values that were available in the record before the update with the values you are updating with. Depending on the result of the comparison you can write an entry to your audit table.