That's news to me. http://www.simple-talk.com/sql/learn-sql-server/in...
Great feature.
It has some pros and cons, though. Maybe it's a matter of finetuning, but for example I wouldn't log a record as it was before an update in the _CT table, that should already be the last state. It may not, if CDC was disabled in between changes.
I perhaps also wouldn't log the insert, I see the audit table as a log of what a record has been and the current data in the main table, so I'd only log update and delete operations, but not inserts. It's a matter of tastes and of needs.
I like the idea of the update mask and overall it's nice and quite easy to setup, much easier thatn triggers.
On the other side, if that better fits your need, you also find triggers, that only log the condensed information about fields changed, instead of always copying the full record, eg an audit entry contains table, field, oldval, newval. That can be shorter for simple updates and much more verbose, if all fields of a record are really changed.
Logging full records has one big advantage: It's very simple to retrieve a record as it was at a certain time, if the table contains a timestamp field or you add it a least to your audit table. But in many situations and applications only some fields of a table are changed.
I wonder, if it would always be faster, if you eg can't turn off the logging of insert and the beforeupdate vs afterupdate states of records, CDC has to do more than the trigger. But I agree it certainly has a lower level access to the data and can much easier copy a record via internal function, than you can do in triggers via T-SQL. That's also reflected in some of the meta data CDC stores in the audit _CT table:, namely in the lsn (log sequential numbers) logged, which relate this data to the transaction log.
CDC is robust, at least it should be as a built in feature, triggers have to stand the test of time. Thaat's maybe the best argument for CDC.
If you want this data permanent, you should care about the cleanup job, though, as far as I understand this.
Bye, Olaf. |
|