如何跟踪数据库表中的数据更改 [英] How to track data changes in a database table

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

问题描述

追踪资料库表格变更的最佳方法是什么?

What is the best way to track changes in a database table?

假设您有一个应用程式,其中使用者能够改变存储在某些数据库表中的数据。跟踪所有更改的历史记录的最佳方法是什么,以便您可以显示哪个用户在什么时间更改了哪些数据?

Imagine you got an application in which users (in the context of the application not DB users ) are able to change data which are store in some database table. What's the best way to track a history of all changes, so that you can show which user at what time change which data how?

推荐答案

p>一般来说,如果您的应用程序被分层结构化,那么数据访问层会调用数据库服务器上的存储过程来写数据库更改的日志。

In general, if your application is structured into layers, have the data access tier call a stored procedure on your database server to write a log of the database changes.

在支持此类事件的语言中,面向方面的编程是一种很好的使用技术为这种应用。审计数据库表更改是您通常需要记录所有操作的操作类型,因此AOP可以很好地工作。

In languages that support such a thing aspect-oriented programming can be a good technique to use for this kind of application. Auditing database table changes is the kind of operation that you'll typically want to log for all operations, so AOP can work very nicely.

记住数据库更改将创建大量的数据,并将减慢系统。根据应用程序的大小,使用消息队列解决方案和单独的数据库来执行审计日志可能是明智的。

Bear in mind that logging database changes will create lots of data and will slow the system down. It may be sensible to use a message-queue solution and a separate database to perform the audit log, depending on the size of the application.

使用存储过程来处理这一点,尽管可能有一些工作涉及将用户凭据传递到数据库本身。

It's also perfectly feasible to use stored procedures to handle this, although there may be a bit of work involved passing user credentials through to the database itself.

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

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