我正在开发一个同步数据的应用程序。我们决定使用 CDC 代替 CT,因为我们需要更多信息,但同时我们需要一个函数来返回更改影响它的列,就像使用 CT 一样:
SELECT
CTTable.SYS_CHANGE_OPERATION,
[FNameCh] = CHANGE_TRACKING_IS_COLUMN_IN_MASK(COLUMNPROPERTY(OBJECT_ID('CONTACT_TABLE'),
'contact_name', 'ColumnId'), SYS_CHANGE_COLUMNS),
[LNameCh] = CHANGE_TRACKING_IS_COLUMN_IN_MASK(COLUMNPROPERTY(OBJECT_ID('CONTACT_TABLE'),
'contact_lastname', 'ColumnId'), SYS_CHANGE_COLUMNS),
FROM CHANGETABLE (CHANGES Contacts, @VersionId) AS CTTable
LEFT OUTER JOIN Contacts AS C ON C.CONTACT_ID = CTTable.CONTACT_ID
GO
编辑:
SELECT * , sys.fn_cdc_has_column_changed ('dbo_CONTACT_TABLE', 'contact_name', __$update_mask) AS FNameCh
From cdc.fn_cdc_get_all_changes_dbo_CONTACT_TABLE(@Start_Lsn,@End_Lsn,'all')
which 1 for if the contact_name is changed and 0 if is not.
谢谢