我只是通过打开ALLOW_SNAPSHOT_ISOLATION来启用更改跟踪,执行此查询以打开数据库的更改跟踪
ALTER DATABASE [DatabaseName]
SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 2 DAYS,AUTO_CLEANUP = ON)
最后在桌面上启用它
ALTER TABLE [TableName]
ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF)
现在当我打电话
SELECT *
FROM CHANGETABLE(CHANGES, 0)
我收到此错误消息:
无效的对象名称“ CHANGETABLE”。
数据库版本为SQL Server2012。
CHANGETABLE
如何无效?如何使之工作?我认为它是开箱即用的,因为它是系统功能。它甚至在SQL Server Management Studio中突出显示。在打开变更跟踪和调用CHANGETABLE()
之间,我修改了一些数据。 最佳答案
SELECT * FROM CHANGETABLE(CHANGES MyTableName,@last_version) as SomeAlias
这显示在documentation examples中:
DECLARE @last_sync_version bigint;
SET @last_sync_version = <value obtained from query>;
SELECT [Emp ID], SSN,
SYS_CHANGE_VERSION, SYS_CHANGE_OPERATION,
SYS_CHANGE_COLUMNS, SYS_CHANGE_CONTEXT
FROM CHANGETABLE (CHANGES Employees, @last_sync_version) AS C;
忘记表名将导致
Invalid object name 'CHANGETABLE'
忘记表别名将导致
A table returned by the CHANGETABLE function must be aliased.