This article (Part II) discusses the intrinsic of CDC as one of the feature (of SQL server 2008 and higher) for providing the data auditing abilities
In the previous article (http://www.dotnetfunda.com/articles/article1924-cdc-in-sql-server-2008-r2-part-i.aspx), we discussed about
auditing needs in general and solutions for data auditing. Also we saw how to
implement CDC and consequent results.
In this article, we would dive deep to know
what the architecture of CDC and how it is structured in the SQL server 2008.
about the intrinsic of CDC feature of SQL server (version 2008 and higher) To learn
about the intrinsic of CDC feature of SQL server (version 2008 and higher)
2008 R2 is referenced and also couple of MSDN articles, image/s are referred for
The diagram which depicts the data flow for
CDC is as below
taken from http://msdn.microsoft.com/en-us/library/cc645937%28v=sql.105%29.aspx)
As seen in the diagram, the data capture
process captures the data from transaction logs resulting better performance by
avoiding overload on DML operations and transactions. The snapshot for captured
changed data is retrieved through the query functions (as shown above) which
are used for data warehouse.
CDC database tables
After reading the transaction logs, it
populates the change tables. This change tables are mentioned in the Part I
still we would revisit them.
Apart from the last one, these are kind of
system table for CDC and actual data would be captured in separate tables which
would correspond to the database tables for which CDC is to be enabled (as
indicated last in the list)
CDC Database Stored Procedures
Following stored procedures are created in
database as a part of enabling the CDC for particular database.
These are employed for
Manage (i.e. create and run)
the CDC agent jobs
Provide the metadata to CDC
consumers i.e. the one who would be utilizing CDC which could be a data
warehouse of simple system for display history
CDC Database Functions
Following functions are created to retrieve
the information about the changes which are captured as part of CDC.
The last 2 functions returns the rows for
change applied for data. Other functions are administrative and related to meta
SQL Server Agent Jobs
There are 2 SQL server agent jobs for CDC
To populate the change tables à Capture Job
To clean-up the change tablesà Clean-up job
are created through stored procedures once a database table is enabled for CDC.
The “Capture Job” starts immediately and removed when CDC is disabled for
database. The creation and removal can be controlled by administrators.
Limitations of CDC
CDC doesn’t support the capturing of
changes in case of computed columns, usage of column-set in case of sparse
columns. For timestamp data type the data is converted into binary.
Querying and meta data
Let’s check out for the columns in the
tables meant for captured data.
__$operation denotes the database operation
1: DELETE 2:
INSERT 3: Before UPDATE 4: After UPDATE
: It’s a Log Sequence Number (LSN) of
data type binary(10) and is common in one transaction.
: Meant for informational purpose
: Represents a sequence value for order (sequence) in a transaction
: Serves as a bit mask for identifying which columns from change tables are
The data auditing through CDC is really
useful feature. In the part I of this series we saw practical example. We
delved deep in CDC intrinsic and touch based the data flow overview, the stored
procedures, agent jobs and querying etc. in this part.
Definitely there is a bit of administrative
and monitoring overhead involved in CDC but it is taken care by the atomic,
unified, configurable execution of capturing the changed data.
Hope these articles have helped to
understand the minimum fundamental aspects of CDC for actual implementation and
also implementation steps.
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.