我试图通过传递最小和最大日期来获得启用 CDC 的表的净变化。但是抛出错误。
Msg 313, Level 16, State 3, Line 24
An insufficient number of arguments were supplied for the procedure or function cdc.fn_cdc_get_net_changes_ ... .
我的代码如下:
DECLARE @CDate DATE = '2013-03-18' --This is the date after the CDC was enabled on the table
DECLARE @count INT;
DECLARE @lsnStartDatetime DATETIME;
DECLARE @lsnEndDateTime DATETIME;
DECLARE @begin_time DATETIME ,
@end_time DATETIME ,
@from_lsn BINARY(10) ,
@to_lsn BINARY(10);
SELECT @lsnStartDatetime = CAST(CAST(@CDate AS NVARCHAR(10)) + ' 00:00:00' AS DATETIME)
SELECT @lsnEndDateTime = CAST(CAST(@CDate AS NVARCHAR(10)) + ' 23:59:59' AS DATETIME)
SET @from_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than or equal',
@lsnStartDatetime);
SET @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal',
@lsnEndDateTime);
if exists (select * from sys.objects where name = 'EmployeeCDCbyDate' and type = 'u')
drop table etl.EmployeeCDCbyDate
SELECT *
FROM cdc.fn_cdc_get_net_changes_employee(@from_lsn, @to_lsn, N'all')
从 sys.fn_cdc_map_time_to_lsn 获取的 from_lsn 和 to_lsn 是否与 cdc 表“员工”不匹配?
下面的代码工作正常;但它会从 min max lsn 获得所有净变化。
DECLARE @min_lsn BINARY(10) = sys.fn_cdc_get_min_lsn ('employee')
DECLARE @max_lsn BINARY(10) = sys.fn_cdc_get_max_lsn ()
SELECT * FROM cdc.fn_cdc_get_net_changes_employee(@min_lsn, @max_lsn, 'all') ORDER BY 1 desc
我需要的是获取给定日期的 cdc 实例的最小和最大 lsn,并获取该日期的净变化。有什么线索吗?
编辑:
当我在一堆表上启用时,这适用于第一个表。
前任:
USE ERP
EXEC sys.sp_cdc_disable_db
EXEC sys.sp_cdc_enable_db
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo',
@source_name = N'Employee',
@capture_instance = 'Employee',
@supports_net_changes =1,
@role_name = NULL
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo',
@source_name = N'StoreListing',
@capture_instance = 'StoreListing',
@supports_net_changes =1,
@role_name = NULL
Go
这适用于 Employee 表。如果我更改启用 CDC 的顺序(如果我将商店列表放在首位,然后将员工放在下一个),那么它适用于员工列表。