如何对存储在mysql中的数据进行版本控制 [英] How to version control data stored in mysql

查看:646
本文介绍了如何对存储在mysql中的数据进行版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一个简单的mysql数据库,但是对其进行了调整,以便将每个字段备份到不确定数量的版本.我可以举例说明的最好方法是,将每个表的每个字段替换为该字段曾经拥有的所有值的堆栈(每个值都应加上时间戳).我想这有点像为我的所有数据定制版本控制..

I'm trying to use a simple mysql database but tweak it so that every field is backed up up to an indefinite number of versions. The best way I can illustrate this is by replacing each and every field of every table with a stack of all the values this field has ever had (each of these values should be timestamped). I guess it's kind of like having customized version control for all my data..

关于如何执行此操作的任何想法?

Any ideas on how to do this?

推荐答案

向表跟踪任何更改"的常用方法是在表上添加插入/更新/删除触发器过程,并将这些记录保存在历史记录中桌子.

The usual method for "tracking any changes" to a table is to add insert/update/delete trigger procedures on the table and have those records saved in a history table.

例如,如果您的主数据表是"ItemInfo",那么您还将拥有一个ItemInfo_History表,该表每次进行任何更改(通过触发器)时都会获得新记录的副本.

For example, if your main data table is "ItemInfo" then you would also have an ItemInfo_History table that got a copy of the new record every time anything changed (via the triggers).

这可以使主表的性能保持一致,但可以根据需要访问任何更改的历史记录.

This keeps the performance of your primary table consistent, yet gives you access to the history of any changes if you need it.

以下是一些示例,它们用于SQL Server,但它们演示了逻辑:

Here are some examples, they are for SQL Server but they demonstrate the logic:

我的存储库表 我的存储库历史记录"表 我的存储库插入触发过程 我的存储库更新触发过程

My Repository table My Repository History table My Repository Insert trigger procedure My Repository Update trigger procedure

这篇关于如何对存储在mysql中的数据进行版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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