Introduction
In this article, we will learn about Change Data Capture (CDC) in SQL Server. which records database activity when tables and rows are changed. Change data capture is often accessible in SQL Server, Azure SQL Managed Instance, and Azure SQL Database.
Change Data Capture (CDC) in SQL Server
CDC captures inserts, updates, and deletes activity on SQL tables. CDC contains a column structure that is the same as the column structure of the source table; in other words, it mirrors the column structure of the tracked source table along with the metadata required to understand changes done in the table's data.
CDC is for providing information about the DML (Data Manipulation Language) changes on the table and database. It helps us to remove expensive techniques like a trigger, timestamp column, and complex join queries.
To use CDC, it must be configured.
Setup & Configure CDC in SQL Server
To use CDC, it must be enabled at the database level; by default, it is disabled. To allow CDC to, you must be a member of "SYSADMIN" (Fixed role of SQL Server). You can enable CDC only on a user Database, not a system database.
To determine whether a database is CDC-enabled, run the following T-SQL.
select name, is_cdc_enabled from sys.databases

To enable CDC on a database, use the system-stored procedure called "SYS.SP_CDC_ENABLE_DB."Execute the following T-SQL.
USE AdventureWorks
Go
EXEC sys.sp_cdc_enable_db
GO

The following CDC tables are created under the CDC schema.
- cdc.captured_columns
- cdc.change_tables
- cdc.ddl_history
- cdc.index_columns
- cdc.lsn_time_mapping
The next step is to enable CDC on a table to track changes in the table data.

USE AdventureWorks
GO
EXEC sys.sp_cdc_enable_table
@source_schema = 'dbo',
@source_name = 'Customer',
@role_name = 'cdc_Customer'
GO

The sys.sp_cdc_enable_table system stored procedure has a few parameters.

While Enabling CDC will create certain stored produce, SQL job, and function.






hitesh nirmalPosted Jan 17, 2014, 3:23 AM
Good explanation.......................
Maria JohnsonPosted Feb 22, 2012, 11:43 PM
You have presented your article in such a way that everyone will love to read it. Thanks for sharing.
Amit MaheshwariPosted Feb 21, 2012, 11:07 PM
It's a well explanation you have give to us about the CDC in SQL Server 2008, SO keep it up and thanks for sharing...
James LerdorfPosted Feb 21, 2012, 10:53 PM
Thanks for this great article and keep it sharing.