Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track data changes in a database table

Tags:

database

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?

like image 793
user3711 Avatar asked Sep 01 '08 21:09

user3711


People also ask

How do you find changes in a table?

We can see all types of changes for a table using SM30 t-code. Here you can see the all table changes log including Z table also. To view the changes log, we have to sure about one thing. Enter you table name, then press display, You will find a technical setting tab.

How do I enable change tracking in SQL table?

If a database contains memory optimized tables, you can't enable change tracking with SQL Server Management Studio. To enable, use T-SQL. You can specify the CHANGE_RETENTION and AUTO_CLEANUP options when you enable change tracking, and you can change the values at any time after change tracking is enabled.


1 Answers

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.

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.

like image 74
Jeremy McGee Avatar answered Sep 29 '22 05:09

Jeremy McGee