SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Difference in CDC vs Trigger


Difference in CDC vs Trigger

Author
Message
yuvipoy
yuvipoy
SSC Eights!
SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)SSC Eights! (848 reputation)

Group: General Forum Members
Points: 848 Visits: 1387
What is the Difference in CDC vs Trigger?
and which one is performance wise a good one to go.

Thanks!
bleroy
bleroy
SSC Veteran
SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)

Group: General Forum Members
Points: 266 Visits: 739
Change Data Capture (CDC) is leveraging the changes applied to the logs as opposed to the actual database, as a result it will "no" impact on your DB performance so it's "better".
One of the downside is that you have to enable it (per DB, per table if memory serves me well) and then get your process up and running.
Triggers will have an impact on the DB performance, due to resources sharing, locks, etc.

CDC is the way to go.

Links:
http://channel9.msdn.com/Blogs/ashishjaiman/CDC-Change-Data-Capture-SQL-Server-2008
http://www.simple-talk.com/sql/learn-sql-server/introduction-to-change-data-capture-(cdc)-in-sql-server-2008/
http://www.sqlservercentral.com/articles/Change+Data+Capture+(CDC)/64289/
http://www.databasejournal.com/features/mssql/implementing-sql-servers-change-data-capture.html

HTH,

B
Gazareth
Gazareth
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4130 Visits: 5843
Although note if you want to capture information like who changed the data, CDC can't do that.
GSquared
GSquared
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24701 Visits: 9730
CDC is A way to go, not necessarily the way to go.

It has some limitations. And, as far as having zero impact, that's partially correct. It doesn't extend the duration of row-locks, but it does require CPU cycles and I/O bandwidth. So it's not really "zero impact", but the impact is often lower than comparable triggers.

As already mentioned, it has limits on being able to do things like capture the user ID, application, connection string, SPID, etc. If all you need is an audit trail of data changes, then CDC can be excellent for this.

CDC also has some limitations with regards to replication, recovery models, and disallows things like truncates on logged tables (note that triggers can't capture truncates either). It also requires that SQL Agent be running (to enable scheduled log-scans). Triggers don't have most of those limitations. (They have other limitations, of course.)

CDC also won't automatically add new columns to a log, while it's relatively easy to set up a DDL trigger to modify a logging trigger. Not an issue if you don't add columns often enough for that to matter, but it can catch people by surprise.

So, which one is better really depends on the purpose of the audit log, and the requirements of the database being audited. If you need Simple Recovery, for whatever reason, then CDC won't do it, but triggers will. If you need zero-impact on locking, then CDC can do that but triggers can't. And so on.

Define the purpose of the audit trail, and you'll get a lot closer to defining which one is better for your needs.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Anthony Perkins
Anthony Perkins
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 662
If you need Simple Recovery, for whatever reason, then CDC won't do it

Just a correction for what it is worth: CDC is supported with Simple Recovery.
ScottPletcher
ScottPletcher
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8338 Visits: 7163
If Change Tracking is enough for what you need it, use it, as it's less overhead than either CDC or a trigger. And it doesn't require Enterprise Edition.

SQL DBA,SQL Server MVP(07, 08, 09)[size=2]Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial: If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.[/size]
JasonClark
JasonClark
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1738 Visits: 1027
CDC is easier to setup and it is only available in SQL Server enterprise edition. CDC do not require creating triggers and storing data.

Triggers are more flexible as user can audit server users and applications etc. Triggers require more planning and management to design triggers and how to store them.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search