Below are some very useful Change Data Capture (CDC) T-SQL Commands.
--Check if cdc is enabled
USE master
GO
SELECT [name], database_id, is_cdc_enabled
FROM sys.databases
GO
--Enabled CDC at database level
USE AdventureWorks
GO
EXEC sys.sp_cdc_enable_db
GO
--Check which tables are CDC enabled
USE AdventureWorks
GO
SELECT [name], is_tracked_by_cdc
FROM sys.tables
GO
--Cnabled CDC for a table
USE AdventureWorks
GO
EXEC sys.sp_cdc_enable_table
@source_schema = N'HumanResources',
@source_name = N'Shift',
@role_name = NULL
GO
--Disable CDC on a table
USE AdventureWorks;
GO
EXECUTE sys.sp_cdc_disable_table
@source_schema = N'HumanResources',
@source_name = N'Shift',
@capture_instance = N'HumanResources_Shift';
GO
--CaptureSelectedColumns
EXEC sys.sp_cdc_enable_table
@source_schema = N'HumanResources',
@source_name = N'Shift',
@role_name = NULL,
@captured_column_list = '[ShiftID],[Name]'
GO
Leave a Reply