From 6286ed20840e53f77841a21e10a458206bcffb10 Mon Sep 17 00:00:00 2001 From: Dipanshu_Kumar Date: Tue, 12 May 2026 10:43:25 +0000 Subject: [PATCH] Add cdc_readme.md --- cdc_readme.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 cdc_readme.md diff --git a/cdc_readme.md b/cdc_readme.md new file mode 100644 index 0000000..4f9668e --- /dev/null +++ b/cdc_readme.md @@ -0,0 +1,70 @@ + +-- CDC +-- Step 1: Check SQL Server Agent +-- Step 2:Enable CDC at Database Level + +Query - EXEC sys.sp_cdc_enable_db; + +--Verify CDC enabled for database + +SELECT name,is_cdc_enabled +FROM sys.databases +WHERE name = 'YourDatabaseName'; + +--if is_cdc_enabled = 1, CDC is enabled. + +--Step 3: Enable CDC for a Table + +EXEC sys.sp_cdc_enable_table + @source_schema = 'dbo', + @source_name = 'Employee', + @role_name = NULL; + +-- Step 4: Verify CDC Enabled for Table +SELECT name,is_tracked_by_cdc +FROM sys.tables +WHERE name = 'Employee'; + +--Step 5: Check CDC Tables + +SELECT * +FROM cdc.change_tables; +--You may see: 'cdc.dbo_Employee_CT' + +-- Step 6: Test CDC +Insert,Update,Delete + +--Step 7: Read CDC Data +SELECT * FROM cdc.dbo_Employee_CT; + +Step 8: Disable CDC (Optional) + +EXEC sys.sp_cdc_disable_table + @source_schema = 'dbo', + @source_name = 'Employee', + @capture_instance = 'dbo_Employee'; + +-- Disable database CDC +EXEC sys.sp_cdc_disable_db; + +-- Important Notes +CDC is available in: +SQL Server Enterprise +Standard Edition (SQL Server 2016 SP1 and later) +Table must have a: +Primary Key (recommended) +Or unique index +SQL Server Agent must remain running + +Architecture Overview +Table Changes + ↓ +Transaction Log + ↓ +CDC Capture Job + ↓ +cdc._CT Table + ↓ +Query CDC Data + +