USE AdventureWorks;
GO
--开启某个数据库的CDC功能
EXEC sys.sp_cdc_enable_db;
GO
--is_cdc_enabled栏位为1代表开启CDC功能了
SELECT name, is_cdc_enabled
FROM sys.databases WHERE database_id = DB_ID();
USE AdventureWorks;
GO
--开启单张表的CDC功能
EXECUTE sys.sp_cdc_enable_table
@source_schema = N’HumanResources’
,@source_name = N’Employee’
,@role_name = N’cdc_Admin’
,@capture_instance = N’HumanResources_Employee’
,@supports_net_changes = 1;
--关闭单张表的CDC功能
EXECUTE sys.sp_cdc_disable_table
@source_schema = N’HumanResources’,
@source_name = N’Employee’,
@capture_instance = N’HumanResources_Employee’;
--检查表是否开启CDC功能
SELECT [name], is_tracked_by_cdc FROM sys.tables
WHERE [object_id] = OBJECT_ID(N’HumanResources.Employee’);
--Alternatively, use the built-in CDC help procedure
EXECUTE sys.sp_cdc_help_change_data_capture
@source_schema = N’HumanResources’,
@source_name = N’Employee’;
GO