SQL

Enable Change Tracking in SQL Server in 4 Steps

7 min read

Change tracking in SQL Server tells your application which rows are new, edited or deleted since the last sync. Microsoft built the feature to replace trigger and timestamp solutions with a synchronous and lightweight option.

Four steps below enable change tracking on a database and a table, query the modified rows and plan the retention. Every step names the setting that decides the result.

Quick SummaryEnable change tracking in SQL Server in four steps. Set the database compatibility level to 90 or higher first. Enable change tracking on the database with a retention period. Enable it on every table that you sync. Query the modified rows with CHANGETABLE and store the version after every sync.

What Does Change Tracking Record in SQL Server?

Microsoft states that change tracking records the fact that a row was modified. It stores the primary key values of the row and returns them with the type of the operation. It does not store the old data or the new data.

Your application opens the current row from the table and compares it with its own copy. The method suits one way and two way sync between a database and an app.

Feature Change tracking Change data capture
What it stores The primary key of the modified row and the operation The row data from before and after the modification
How it works Synchronous. It records the fact inside your transaction Asynchronous. It scans the transaction log
History No data history Stores history in change tables
Edition Available on the editions of SQL Server Needs Standard or Enterprise and the Agent capture task
Storage cost Small Larger because it stores the row data

Microsoft states that you can enable both features on the same database. The post on auditing data modifications in SQL Server explains the other ways to audit modifications.

Do You Know?Choose change tracking when your app needs to know which rows to sync. Choose change data capture when you need the values of the old and the new row.

Which Setting Matters in Your Case?

Your situation Setting to decide Risk
The app syncs once a day Retention of at least 2 days Clients below the minimum valid version must reload all rows
You need the names of the edited columns TRACK_COLUMNS_UPDATED set to ON Extra storage for the column data
The sync query executes while users edit Snapshot isolation Open snapshot transactions can retain expired rows in sys.syscommittab
The database has memory optimized tables Use T-SQL and not SSMS SSMS cannot enable the feature for such databases

How Do You Enable Change Tracking in SQL Server?

Step 1: Check the Compatibility Level

Microsoft states that the compatibility level must be 90 or higher for CHANGETABLE. Check the level before you enable the feature.

SELECT name, compatibility_level
FROM sys.databases
WHERE name = N'SalesDB';

Raise the level only after you test your queries. The post on database compatibility level and performance explains the effect on plans.

Step 2: Enable Change Tracking on the Database

Set the retention period and the automatic cleanup in one statement. Microsoft states that the retention period must be at least as long as the maximum time between two syncs.

ALTER DATABASE SalesDB
SET CHANGE_TRACKING = ON
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON);

A short retention frees space sooner and a client that returns late must reload. A long retention uses more space.

Heads UpMicrosoft states that SSMS cannot enable change tracking on a database with memory optimized tables. Use the T-SQL statement.

Step 3: Enable Change Tracking on the Tables

Enable the feature on every table that your app syncs. Set TRACK_COLUMNS_UPDATED to ON when you need the columns that were modified. The default is OFF.

USE SalesDB;

ALTER TABLE dbo.Orders
ENABLE CHANGE_TRACKING
WITH (TRACK_COLUMNS_UPDATED = ON);

SELECT DB_NAME(database_id) AS database_name, retention_period,
       retention_period_units_desc, is_auto_cleanup_on
FROM sys.change_tracking_databases;

SELECT OBJECT_NAME(object_id) AS table_name, is_track_columns_updated_on
FROM sys.change_tracking_tables;

The two catalog views confirm the database settings and the table settings. An empty result means that the feature is off.

Step 4: Query Modified Rows With CHANGETABLE

Store the version after every sync. Your app passes the stored version to CHANGETABLE and gets the primary keys of the rows modified since then. Microsoft recommends snapshot isolation so the version and the data match.

DECLARE @last_sync_version bigint = 0;
DECLARE @current_version bigint;

SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
BEGIN TRANSACTION;

SET @current_version = CHANGE_TRACKING_CURRENT_VERSION();

IF @last_sync_version < CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(N'dbo.Orders'))
    SELECT N'Reload all rows' AS action;
ELSE
    SELECT CT.OrderID, CT.SYS_CHANGE_OPERATION, CT.SYS_CHANGE_COLUMNS, O.Status
    FROM CHANGETABLE(CHANGES dbo.Orders, @last_sync_version) AS CT
    LEFT OUTER JOIN dbo.Orders AS O
      ON O.OrderID = CT.OrderID;

COMMIT TRANSACTION;

SYS_CHANGE_OPERATION shows I for an insert and U for an update and D for a delete. The outer join returns deleted rows because the table no longer has them. Save the value of @current_version as the next @last_sync_version.

Microsoft states that a client with a version below CHANGE_TRACKING_MIN_VALID_VERSION must reload all rows. The post on snapshot isolation in SQL Server explains the setting that the query uses.

How Does Cleanup Remove Old Tracking Entries?

Automatic cleanup deletes the entries that are older than the retention period. SQL Server 2022 and earlier start the cleanup every 30 minutes. SQL Server 2025 uses adaptive shallow cleanup by default and trace flag 8273 disables it.

Item What Microsoft states
Cleanup interval Every 30 minutes in SQL Server 2022 and earlier
SQL Server 2025 Adaptive shallow cleanup is the default. Trace flag 8273 disables it
Disable order Disable change tracking on the tables first and then on the database
Open snapshot transactions Can retain expired rows in sys.syscommittab
ALTER TABLE dbo.Orders
DISABLE CHANGE_TRACKING;

ALTER DATABASE SalesDB
SET CHANGE_TRACKING = OFF;

Common Questions on Change Tracking in SQL Server

Does Change Tracking Store the Old Values of a Row?

No. Microsoft states that change tracking records only that a row was modified and stores its primary key. Use change data capture when you need the old and the new values.

What Happens When a Client Syncs After the Retention Period?

The stored version of the client is below the minimum valid version. The client must reload all rows. Choose a retention period that is longer than the longest gap between syncs.

Can You Use Change Tracking and Change Data Capture Together?

Yes. Microsoft states that you can enable both on the same database. Change tracking records which rows to sync and change data capture stores the data history.

Which Compatibility Level Does Change Tracking Need?

Microsoft states that CHANGETABLE needs a compatibility level of 90 or higher.

How Do You Disable Change Tracking?

Disable it on the tables first and then on the database. The two ALTER statements in the cleanup section show the order.

Who, How and WhyAndrew Jackson, Technical Content Specialist, is the author of this guide. The feature description, the enable statements and the retention rule follow the Microsoft page on enabling and disabling change tracking. The CHANGETABLE and version functions follow the Microsoft page on working with change tracking. The comparison with change data capture follows the Microsoft overview of change tracking. The code was checked for syntax against Microsoft documentation and was not executed on a live server. The fetched pages did not state a primary key requirement and this guide makes no claim about it. Verify every step on your version. The guide exists because sync apps need a small and reliable list of the rows that moved.

Key Takeaways

  • Change tracking records the primary key of a modified row and the operation. It does not store the old or the new data.
  • Retention must be at least as long as the longest gap between two syncs. A client below the minimum valid version must reload all rows.
  • Enable the feature on the database first and then on every table. Disable it in the opposite order.
  • CHANGETABLE needs a compatibility level of 90 or higher.
  • Snapshot isolation aligns the version with the data while the sync query executes.
  • SQL Server 2025 uses adaptive shallow cleanup by default.