Capture DDL Changes using Change Data Capture with SQL Server 2008

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:

Use ChangeDataCapture
Create table Currency
CurrencyKey Int Identity(1,1) Primary Key NOT NULL,
CurrencyAlternateKey varchar(5)

2. Once the Currency table is successfully created, you need 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 below mentioned TSQL Query

Use ChangeDataCapture
EXEC sp_cdc_enable_table  ‘dbo’, ‘Currency’, @role_name = NULL, @supports_net_changes =1

4. Execute the query below to check whether the table is enabled for CDC

Use ChangeDataCapture
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 for is_tracked_by_cdc column means that CDC is disabled.

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 cdc.dbo_Currency_CT name as shown. 

6. Next step will be to alter the Currency table to add the CurrencyName column:

Use ChangeDataCapture
Alter table Currency add CurrencyName varchar(25)

7. The DDL changes which have occurred to the Currency table can be viewed by executing the following TSQL Query:

Use ChangeDataCapture
Select OBJECT_NAME(Source_Object_ID) As [Table Name], 
            OBJECT_NAME(Object_ID) As [CDC Table Name],
                DDL_Command As [DDL Command],
            DDL_LSN As [Log Sequence Number],
            DDL_Time As [DateModified]
From CDC.ddl_history

The Change Data Capture feature helps DBA’s to enable CDC on a database table and keep track of all the Data Defination Language changes on a specific user table.

Pages: 1 2

Related Articles :

  • No Related Articles Found

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |