SQL Server error 1718 occurs when you try to enable Change Tracking on a database but the database does not have it turned on at the database level. The fix is straightforward: run ALTER DATABASE [YourDatabase] SET CHANGE_TRACKING = ON (with optional retention settings) before enabling it on individual tables. This guide walks you through the exact steps, prerequisites, and common pitfalls.
What You'll Need
- SQL Server Management Studio (SSMS) or any query tool with permission to run
ALTER DATABASE. - Login with
ALTERpermission on the database (typicallydb_ownerorsysadmin). - SQL Server version that supports Change Tracking (2008 and later, including Express editions).
- If you plan to use Change Tracking for sync, know the retention period you want (default is 2 days).
Step-by-Step
- Identify the database that is throwing error 1718. The error message usually includes the database name, e.g.,
Msg 1718, Level 16, State 1, Line 1 Change tracking must be enabled on database 'MyDB'. - Open SSMS and connect to the SQL Server instance where the database resides.
- Open a new query window (or use the existing one) and select the context to the master database or the target database. It is safe to run the
ALTER DATABASEstatement from any database context. - Check if Change Tracking is already enabled (optional but useful) by running:
SELECT is_change_tracking_enabled FROM sys.databases WHERE name = 'YourDatabase';
A result of1means it is already on;0means it is off. - Enable Change Tracking at the database level with a simple command:
ALTER DATABASE [YourDatabase] SET CHANGE_TRACKING = ON;
This enables it with default settings (retention = 2 days, auto cleanup = ON). - If you want a custom retention period, add the
CHANGE_RETENTIONclause:
ALTER DATABASE [YourDatabase] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 5 DAYS, AUTO_CLEANUP = ON);
Valid units:DAYS,HOURS,MINUTES. Retention must be between 1 minute and 525,600 minutes (365 days). - After enabling at the database level, you can now enable Change Tracking on individual tables that need it:
ALTER TABLE [YourSchema].[YourTable] ENABLE CHANGE_TRACKING;
Optionally, you can specifyWITH (TRACK_COLUMNS_UPDATED = ON)if you need to know which columns were updated. - Verify the setup by checking the database setting again or querying
sys.change_tracking_tablesto list tables with Change Tracking enabled:
SELECT * FROM sys.change_tracking_tables; - If you are using Change Tracking for sync (e.g., with Azure Data Sync or a custom sync framework), you may also need to enable it on the primary key columns—but that is automatic when you enable it on a table with a primary key.
- If the database is part of an Always On availability group, enable Change Tracking on the primary replica; it will automatically propagate to secondaries. Do not enable it separately on secondaries.
Common Mistakes
- Enabling Change Tracking only on tables without first enabling it on the database. This is the direct cause of error 1718.
- Using the wrong syntax—some people try
ALTER DATABASE ... SET CHANGE_TRACKING = ONbut miss the database name or use square brackets incorrectly. - Forgetting to specify a retention period when you need a longer history. The default 2 days may be too short for some sync scenarios.
- Running the command in the wrong database context—if you run
ALTER DATABASEwithout specifying the database name, it will try to alter the current database, which may not be the one you intended. - Assuming Change Tracking is enabled by default—it is not. You must explicitly enable it per database.
- Not having sufficient permissions—if you are not a db_owner or sysadmin, the command will fail with a permission error, not error 1718. Ensure you have the right role.
Tips
- Plan your retention period based on how often your sync process runs. If you sync every hour, a retention of 1 day is usually enough. If you sync weekly, set it to 8 days or more.
- Use the
CHANGE_RETENTIONclause to avoid cleanup issues. Auto cleanup is ON by default, but you can disable it if you want manual control (not recommended for most cases). - Test in a development environment first. Enabling Change Tracking adds overhead to DML operations, so verify performance impact before enabling on production.
- Remember that Change Tracking is different from Change Data Capture (CDC). Error 1718 is specifically about Change Tracking. If you need CDC, that is a separate feature with different requirements (Enterprise edition only).
- If you are using Azure SQL Database, the syntax is the same, but you must be connected to the master database to run
ALTER DATABASE. - Keep a script of the exact command you used, so you can replicate it on other databases or in deployment pipelines.
Troubleshooting
If the steps above do not resolve the issue, try the following in order:
- Check the error message again—make sure it is indeed error 1718 and not a different error like 170 or 2714. Error 1718 specifically says “Change tracking must be enabled on database”.
- Verify your SQL Server version—Change Tracking is available in SQL Server 2008 and later, including Express. If you are on an older version, you cannot use it.
- Ensure you are not trying to enable Change Tracking on a system database (master, model, msdb, tempdb). Change Tracking is not supported on system databases.
- Check if the database is in a state that does not allow Change Tracking—for example, a database in read-only mode or offline. You must bring it online and make it writable first.
- If the
ALTER DATABASEcommand fails with a different error, look at the specific error code. Common ones include permission denied (error 262) or invalid retention period (error 15600). - If you are using an availability group, ensure you are connected to the primary replica. Change Tracking cannot be enabled on a secondary replica directly.
- Restart the SQL Server service after enabling Change Tracking if you encounter odd behavior—this is rarely needed but can help clear metadata caches.
- If all else fails, drop and recreate the database (only if you have a backup) and reapply the Change Tracking settings. This is a last resort because it deletes all data in that database—make sure you have a full backup before doing this.
Frequently Asked Questions
Q: Can I enable Change Tracking on a table without enabling it on the database?
No. The database-level setting is a prerequisite. You must enable it on the database first, then on each table.
Q: What is the default retention period for Change Tracking?
The default is 2 days. You can change it when you enable Change Tracking or later with ALTER DATABASE ... SET CHANGE_TRACKING = ON (CHANGE_RETENTION = ...).
Q: Does enabling Change Tracking slow down my database?
Yes, there is some overhead on DML operations (INSERT, UPDATE, DELETE) because SQL Server tracks changes. The impact is usually small but can be significant on high-transaction tables. Monitor performance after enabling.
Q: Can I use Change Tracking with Azure SQL Database?
Yes, Azure SQL Database supports Change Tracking. The syntax is the same, but you must run ALTER DATABASE while connected to the master database.
Q: How do I disable Change Tracking if I no longer need it?
Use ALTER DATABASE [YourDatabase] SET CHANGE_TRACKING = OFF to disable it at the database level. This will automatically disable it on all tables. You can also disable it on individual tables with ALTER TABLE [YourTable] DISABLE CHANGE_TRACKING.
Q: Does Change Tracking work on tables without a primary key?
No, Change Tracking requires a primary key on the table. If you try to enable it on a table without a primary key, you will get an error.
If you have followed all steps and still encounter error 1718, double-check that you are running the ALTER DATABASE command on the correct server and that the database name is spelled correctly. The solution is always to enable Change Tracking at the database level before touching any tables.