在MySQL中更改数据捕获 [英] Change Data Capture in MySQL

查看:196
本文介绍了在MySQL中更改数据捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我想跟踪列的值是否发生变化.以这种方式,使字段的每个时间值都发生变化,我们可以知道以前的值是什么.为每个值分配时间戳会很棒更改.我将MySQL用作数据库服务器.

In my database I want to track the value of a column whenever it is changed .In a way such that every time value of a field changes we can know what was the previous value .It would be awesome to assign timestamps to each change.I am using MySQL as the database server.

推荐答案

为此,您需要创建一个触发器,该触发器是在给定表上出现INSERT, UPDATE, DELETE时触发的事件.

To do that you need to create a trigger, which is an event that is fired when an INSERT, UPDATE, DELETE occurs on a given table.

请参阅创建触发器的文档.

对于您要执行的操作,可能需要有一个辅助表,该表在主表上为每个INSERT/UPDATE插入了一行,而AFTER它包含更改的行ID,旧值新值和时间戳.

For what you want to do, you probably need to have an auxiliary table that has a row inserted for each INSERT/UPDATE on the main table, AFTER it happens containing the ID of the row changed, the old value the new value and a timestamp.

这篇关于在MySQL中更改数据捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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