3

我刚刚通过打开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 Server 2012,怎么CHANGETABLE会失效,怎么让它工作?我认为它可以开箱即用,因为它是一个系统功能。它甚至在 SQL Server Management Studio 中突出显示。我在打开更改跟踪和调用之间修改了一些数据CHANGETABLE()

4

1 回答 1

4

正确的语法

SELECT * FROM CHANGETABLE(CHANGES MyTableName,@last_version) as SomeAlias

这显示在文档示例中:

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.

于 2019-03-21T15:49:07.843 回答