Site sponsored by: Idera The gold standard of SQL Server performance monitoring & diagnostics.
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Recover Data Using Database Snapshots
Analyze and Fix Index Fragmentation in SQL Server 2008
Powerful Geographical Visualisations made easy with SQL 2008 Spatial (Part 2) ...
Backup User Databases Using a Maintenance Plan

More     
 
Latest FAQ's

How to alter a User Defined Data Type?
How to unzip a File in SSIS?
How to view previous query plans?
ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> general dba >> Capture DDL Changes using Change Data Capture ...

Capture DDL Changes using Change Data Capture with SQL Server 2008

By : Ashish Kumar Mehta
Jul 23, 2008

Page 2 / 2


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
Go
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
Go
EXEC sp_cdc_enable_table  'dbo', 'Currency', @role_name = NULL, @supports_net_changes =1
Go




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

Use ChangeDataCapture
Go
Select [name], is_tracked_by_cdc from sys.tables
GO


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
Go
Alter table Currency add CurrencyName varchar(25)
Go


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

Use ChangeDataCapture
Go
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
Go




Conclusion
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.


<< Prev Page         








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved