MySQL:如何获取上次更新的更改 [英] MySQL: How to get changes of last UPDATE

查看:234
本文介绍了MySQL:如何获取上次更新的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL和PHP开发数据库应用程序.目前,我正在尝试获取由上一次UPDATE引起的更改.我解决问题的第一个方法是

I am working on a database application with MySQL and PHP. At this moment I'm trying to get the changes caused by the last UPDATE. My first way to solve the problem is

  • 通过SELECT获取旧"状态
  • 使用UPDATE进行更改
  • 通过SELECT获取新"状态
  • 用php比较数组

这是三个mysql连接...

These are three mysql-connections...

有什么办法可以缩短这个时间?

Is there any way to shorten this?

推荐答案

您可以执行更新触发器之前,它将记录的整个副本推送到历史记录表,该表还包含您希望存储的其他状态数据(更新日期,用户等)

You could do an before update trigger that will push an entire copy of the record to a history table that also contains additional state data you wish to store (updated date, user etc.)

这样,您将拥有有关什么记录发生了什么的完整修订历史,并且应该透明地发生.只想记住的是,您应该从历史记录表中删除所有唯一约束.

This way you will have a complete revision history of what happened with what records and it should happen transparently. only think to remember is you should drop any unique constraints from the history table.

希望这会有所帮助.

这篇关于MySQL:如何获取上次更新的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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