-SQLSERVER开启CDC:
–查看数据库是否启用cdc:
SELECT name ,is_cdc_enabled FROM sys.databases WHERE is_cdc_enabled = 1
–查看当前数据库表是否启用cdc:
SELECT name ,is_tracked_by_cdc FROM sys.tables WHERE is_tracked_by_cdc = 1
第一步当前数据库启用cdc:
USE 库名
GO
EXECUTE sys.sp_cdc_enable_db;
GO
第二步开启表CDC:
IF EXISTS(SELECT 1 FROM sys.tables WHERE name='table' AND is_tracked_by_cdc = 0)
BEGIN
EXEC sys.sp_cdc_enable_table
@source_schema = 'dbo',
@source_name = '表名',
@capture_instance = NULL,
@supports_net_changes = 1,
@role_name = NULL,
@index_name = NULL,
@captured_column_list = NULL,
@filegroup_name = 'CDC'
END
GO
删除CDC:
-- 对表停止捕获
USE 库名;
GO
EXEC sys.sp_cdc_disable_table
@source_schema = 'dbo' ,
@source_name = '表名' ,
@capture_instance = 'dbo_CDC_Test'
GO
-- 对数据库禁用变更数据捕获
USE 库名;
GO
EXECUTE sys.sp_cdc_disable_db;
GO
--执行完成后,相关的表、函数、用户、角色、架构、作业都会完全删除!