Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 change data capture vs triggers in audit trail

We have audit trail implemented using triggers on our web application. Those triggers log field level updates. So, in a table, if you have 5 column values changed, we have 5 records in the audit trail one for each column with old value and the new value.

Recently we have upgraded to SQL Server 2008. I have been thinking of using the new change data capture feature as it gives a very neat row level update with very less efforts and it's super-easy to implement. Just wanted to get some opinions from people who have been using change tracking for any caveat or any other real-world useful info on this.

Any advice would be helpful.

Edit :- http://technet.microsoft.com/en-us/magazine/2008.11.sql.aspx?pr=blog

like image 966
Ashish Gupta Avatar asked Apr 08 '12 04:04

Ashish Gupta


People also ask

Does Change Data Capture affect performance?

Trigger-based CDC can impact the performance of the source database because triggers run on the database tables as data changes are made. With every transaction, it takes compute cycles to record the change in a separate table, so the system is slowed by this extra processing.

What is change data capture SQL Server?

Change data capture (CDC) uses the SQL Server agent to record insert, update, and delete activity that applies to a table. This makes the details of the changes available in an easily consumed relational format.

Why do we need change data capture?

Benefits of Change Data Capture Ultimately, CDC will help your organization obtain greater value from your data by allowing you to integrate and analyze data faster—and use fewer system resources in the process.

What is trigger in auditing?

The common one is using auditing triggers in SQL Server databases. A trigger is a special type of a database object which is automatically executed upon certain conditions – e.g. actions performed by the user.


1 Answers

I use CDC in my WPF app. Works very well but I've discovered three problems:

  • You need to back-up change tables quite often (I use MERGE statement to add records to historical tables). Because record stays in change table only for about 2-3 days as I found out. Don't forget to backup cdc.lsn_time_mapping table.
  • You can't truncate tables with CDC enabled.
  • There is a problem with disabling cdc and reenabling (should be solved in new service pack as MS said). I've got this problem only once so it's not so annoying.

    http://blogs.technet.com/b/claudia_silva/archive/2010/06/04/cdc-cdc-hangs-when-i-try-to-disable-it.aspx

Anyway, CDC is very useful mechanism which helps me track all changes on database.

like image 124
devarc Avatar answered Oct 14 '22 11:10

devarc