Sql-server – Change data capture – how to know who made the change

change-data-capturesql-server-2012

Tracking who made the change identified by CDC.

Along the lines of my datetime hack I tried the same approach by adding suser_sname as a new field with default value on the cdc change track table. But, that seems to return the owner of the cdc process and not the user who initiated the change on the base table. I also tried original_login but that returns the sql service account login. Again, likely associated with the cdc process and not the user who initiated the change.

I found a similar question on stack-overflow but with no answer other than tracking changes from the front end or via a trigger, which seems to defeat the purpose of using cdc. I wouldn't repost but since the original was on stackoverflow I thought I'd give it a try here especially if R2 or 2012 has introduced a better way.

So, in short: How do I know who made the change in change data capture?

Best Answer

I filed a bug about this, but it was closed as "by design."

http://connect.microsoft.com/SQLServer/feedback/details/283707/cdc-options-to-capture-more-data-username-date-time-etc

Unfortunately you will have to use another technique (e.g. SQL Audit or a trigger) to get this information (and some custom code to try to correlate it to the CDC data as much as you can). I wrote about this deficiency also in my chapter "SQL Server Audit, Change Tracking, and Change Data Capture" in the book SQL Server MVP Deep Dives (volume 1).

I'm sorry that I don't have a better workaround for you but the built-in capabilities of CDC just aren't going to meet your requirements. :-(