The CHANGETABLE function is typically used in the FROM clause of a query as if it were a table.
To obtain row data for new or modified rows, join the result set to the user table by using the primary key columns. Only one row is returned for each row in the user table that has been changed, even if there have been multiple changes to the same row since the last_sync_version value.
Primary key column changes are never marked as updates. If a primary key value changes, it is considered to be a delete of the old value and an insert of the new value.
If you delete a row and then insert a row that has the old primary key, the change is seen as an update to all columns in the row.
The values that are returned for the SYS_CHANGE_OPERATION and SYS_CHANGE_COLUMNS columns are relative to the baseline version that is specified. For example, if an insert operation was made at version 10 and an update operation at version 15, and if the baseline is last_sync_version is 12, an update will be reported. If the last_sync_version value is 8, an insert will be reported. SYS_CHANGE_COLUMNS will never report computed columns as having been updated.
Generally, all operations that insert, update, or delete of data in user tables are tracked, including the MERGE statement.
The following operations that affect user table data are not tracked:
-
Executing the UPDATETEXT statement
This statement is deprecated and will be removed in a future version of SQL Server. However, changes that are made by using the .WRITE clause of the UPDATE statement are tracked.
-
Deleting rows by using TRUNCATE TABLE
When a table is truncated, the change tracking version information that is associated with the table is reset as if change tracking has just been enabled on the table. A client application should always validate its last synchronized version. The validation fails if the table has been truncated.
An empty result set is returned if a nonexistent primary key is specified.
The value of SYS_CHANGE_VERSION might be NULL if a change has not been made for longer than the retention period (for example, the cleanup has removed the change information) or the row has never been changed since change tracking was enabled for the table.