SQL Server 2008 Capture DML Changes Using Change Data Capture
How to Configure CDC for a SQL Server 2008 Database Table
1. Now let’s create the Currency Table in ChangeDataCapture Database by executing the following TSQL Query:
Create table Currency
CurrencyKey Int Identity(1,1) Primary Key NOT NULL,
2. Once the Currency table is successfully created, a DBA needs to make sure that the SQL Server Agent Service is running. In order for the CDC to be successful the SQL Server Agent should be running.
3. Enable CDC for the table Currency by executing the following TSQL Query:
EXEC sp_cdc_enable_table ‘dbo’, ‘Currency’, @role_name = NULL, @supports_net_changes =1
4. Execute the following query to check whether the table is enabled for CDC:
Select [name], is_tracked_by_cdc from sys.tables
The value of 1 for the is_tracked_by_cdc column means that CDC is enabled for the table and the value of 0 means that CDC is not enabled.
5. Once you have enabled CDC for the Currency table, another table is created for keeping changed data and the information about the changes in the source table. The new table created will have the cdc.dbo_Currency_CT name and the same is highlighted in the above image.
6. Let’s insert a few rows to the Currency table:
Insert into Currency Values (‘AFA’,’Afghani’)
Insert into Currency Values (‘INR’,’Indian Rupee’)
Insert into Currency Values (‘JPY’,’Yen’)
Insert into Currency Values (‘USD’,’US Dollar’)