Thursday, September 20, 2012

Change Data Capture (CDC)

Change data capture provides information about DML changes on a table and a database.

Easy Steps to run TTthe ChangeDataCapture (CDC)




USE [master]
Go
Create Database Change_Data_Capture
Go


Use Change_Data_Capture
Go
EXEC sys.sp_cdc_enable_db
Go


Go
Create table Test
(
TestKey Int Identity(1,1) Primary Key NOT NULL,
TestName varchar(25)
)
              
Use Change_Data_Capture
Go
EXEC sp_cdc_enable_table  'dbo', 'Test', @role_name = NULL, @supports_net_changes =1
Go

----Job 'cdc.Change_Data_Capture_capture' started successfully.
--- Job 'cdc.Change_Data_Capture_cleanup' started successfully.


Use Change_Data_Capture
Go
Select name, is_tracked_by_cdc from sys.tables
Go


insert into Test
select 'R1'
union select 'R2'
union select 'R3'
union select 'R4'

Go
Select * from cdc.dbo_Test_CT
Go

Update Test
Set TestName = 'R1MODIFIED'
Where TestKey = 1
Go

Delete From Test
Where TestKey = 2
Go

Select * from cdc.dbo_Test_CT

Go

delete from Test
Go
Select * from cdc.dbo_Test_CT
Go

truncate table Test
-- Cannot truncate table 'Test1' because it is published for replication or enabled for Change Data Capture.
drop table Test
Go
/*
_$operations = 1 Means row was Deleted
_$operations = 2 Means row was Inserted
_$operations = 3 Means value of row before update
_$operations = 4 Means value of row after update
*/

Go

use master
Go
Drop Database Change_Data_Capture
Go
SQL Server Agent needs to be Started before you run this program.










SQL Server Versions

Microsoft SQL Server is a relational database management system developed by Microsoft.

Version                                Year                         Release Name                                Codename
--------------------------------------------------------------------------------------------------------------------------
1.0(OS/2) (16bit)                  1989                        SQL Server 1.0
1.0(OS/2) (16bit)                  1991                        SQL Server 1.1
4.21(winNT)                        1993                         SQL Server 4.21                            SQLNT
6.0                                        1995                        SQL Server 6.0                               SQL95
6.5                                        1996                        SQL Server 6.5                               Hydra
7.0                                       1998                         SQL Server 7.0                               Sphinx
-                                           1999                         SQL Server 7.0                               Palato mania 
8.0                                       2000                         SQL Server 2000                            Shiloh
8.0(64bit)                            2003                         SQL Server 2000                            Liberty
9.0                                       2005                         SQL Server 2005                            Yukon
10.0                                     2008                         SQL Server 2008                             Katmai
10.25                                   2010                         SQL Azure DB                                CloudDB
10.5                                     2010                         SQL Server 2008 R2                       Kilimanjaro
11.0                                    2012                          SQL Server 2012                             Denali
Thanks