I spent last weekend reading about Change Tracking (CT). I have worked with Change Data Capture (CDC) a couple of times but really never got the right scenario to implement Change Tracking.
CT, like CDC tracks changes to a particular table in a particular database. In many ways, they are similar but their dissimilarities are what will interest you. So here is a quick look in to the similarities and dissimilarities:
How are they similar?
- Both needs to be enabled on per database basis
- Both needs to be enabled on per table basis to track changes in that particular table
- Both create system tables where the change information is recorded
- Both can track whether a column was changed
How are they dissimilar?
- CT only tracks whether a change has been done or not; does not track the data values (old and new). CDC also tracks the data values (old and new)
- CT only gives you the last change (final change) in case a series of changes has been done to the data. CDC gives you the complete history of the changes.
- CT adds a hidden column to the table being tracked to uniquely identify the rows. CDC doesn’t do that.
- CT records changes synchronously. CDC records asynchronously.
- CT uses TempDB. CDC uses transactional log.
- CT doesn’t need SQL Agent. CDC needs SQL Agent.
- CT is available on lower editions. CDC is only available in Enterprise Edition & Higher.
You are welcome add more similarities and dissimilarities in the comments section below.
Now, let me put out an obvious question; what are the right usage scenarios for CT & CDC? Hope to see some answers…
5 Comments on “SQL Server: Similarities and Dissimilarities between Change Tracking and Change Data Capture in SQL Server”
Great post Amit.
CDC sucks…Sorry for using that foul word but it really does.
It does not provide in built ways by which you can understand the login which made the changes.
Do a schema change on a table where CDC is configured I bet you are gonna loose all the tracking that CDC logs.
Sachin, before you display such strong sentiments; I advise you that you should know which feature should be used for which purpose…
Do you know why CDC does not give login name? Was it so difficult for the product team to add another coulmn in the tracking tables displaying the login name?
Here is your answer: CDC stands for Change Data Capture – means this features only cpatures changes to data. Who made the change is an auditing question. And if you want an answer to that, you have to implenment “Full event auditing” in SQL Server 2008.
CDC is primarily built for ETL purposes; and MS team does not want people to start using it for auditing purposes. If that happens, many DBAs might land up using CDC for auditing and will recrod way too much infromation only to get the login name. ANd this become the wrong use of a good feature.. and then another DBA will again complain – it just sucks 🙂
FOr your other question; need to look into implementation…
The reason why I am showing such strong sentiment was because after we had implemented CDC we wanted to add a index on a table.As soon as it was added CDC deleted everything which it had logged and we lost a hell lot audit data.This is not dcoumented anywhere except on some SQL forums and as a community contributor it is our duty to make the readers aware of such issues and not just post the good side of things.
One can easily get carried away in implementing CDC as an auditing tool and then taste the sour fruits of it later.
Also can you please explain what is CDC meant for and “MS team does not want it for auditing purpose” because if you are tracking changes(which CDC does )then it means it is auditing.
Also as far as adding a custom column in the CDC table for displaying login name CDC just does not seems to like that just logs the schema name instead.
As you said Data Auditing is much much more felxible tool and should be used instead of CDC for auditing which we did and works very fine.I totally agree with that…
Great post Amit Bansal and your reply is also very informative.