Upgrading the SQL Server Database Engine and changing a database's compatibility level are separate operations. After moving a database to a newer SQL Server version, you can often keep its previous compatibility level while validating the engine upgrade. This separates infrastructure migration from changes in query-processing behavior.
That separation is useful because compatibility level is not merely a legacy switch. It can influence cardinality estimation, query optimization behavior, selected Transact-SQL behaviors, and the availability of newer query-processing features. Treat the change as a controlled performance rollout rather than as a one-line administrative task.
What does compatibility level control?
A database compatibility level controls Transact-SQL and query-processing behaviors for a specific database. It does not change the behavior of every database on the instance, and different databases on the same SQL Server instance can use different levels.
When a database is moved to a newer engine version, the compatibility setting can remain unchanged. The application can then be tested on the new engine before the newer query optimizer behavior is enabled. After that validation, the database can be moved to the target level in a deliberate step.
A compatibility-level change may affect:
- Cardinality estimation and the optimizer's plan choices.
- Query optimizer fixes and version-specific optimization behavior.
- Some Transact-SQL parsing and runtime behaviors.
- Availability of newer intelligent query-processing features.
- Compilation of stored procedures defined in the affected database.
Compatibility level does not restore removed system objects or changed system catalog columns. It is therefore not a complete application-compatibility guarantee.
Check the current configuration first
Record the current database setting and engine version before making any change:
SELECT d.name, d.compatibility_level, d.state_desc, SERVERPROPERTY('ProductVersion') AS product_version, SERVERPROPERTY('ProductMajorVersion') AS product_major_versionFROM sys.databases AS dWHERE d.name = N'SalesDb';The target value must be supported by the SQL Server version hosting the database. Because supported values evolve across product releases and platforms, confirm the available levels in the current Microsoft documentation instead of relying on a hard-coded compatibility table.
A safer upgrade sequence
1. Separate the engine upgrade from the compatibility change
Move the database to the new SQL Server version while initially retaining its existing compatibility level. This allows you to validate drivers, connection behavior, jobs, maintenance tasks, backup procedures, third-party dependencies, and application functionality before introducing new query-processing behavior.
Also review features that were deprecated, removed, or changed in the target engine version. Compatibility level protects selected behaviors; it does not protect every product change.
2. Establish a Query Store baseline
Before changing the level, confirm that Query Store is enabled and collecting representative data. Let it capture enough of the normal workload to cover important business cycles. A short test window can miss weekly reports, month-end processing, scheduled imports, or low-frequency administrative queries.
Capture metrics that can be compared before and after the change:
- CPU time and elapsed time.
- Logical reads and writes.
- Execution count and error rate.
- Plan changes and performance by plan.
- Completion times for business-critical reports and transactions.
Query Store is valuable here because it shows not only which queries are slow, but also whether the same query began using a different plan after the compatibility change.
3. Apply the new level deliberately
After testing and change approval, use a controlled deployment or maintenance window:
ALTER DATABASE [SalesDb]SET COMPATIBILITY_LEVEL = 160;Record the previous value, the change time, the target value, and the exact rollback command. Many ALTER DATABASE operations can invalidate the affected database's plan cache. Subsequent queries may recompile, so a temporary increase in compilation activity and CPU usage is possible immediately after the change.
4. Monitor both database and application signals
Do not rely only on average query duration. A low-frequency query can be business-critical even if it does not influence the overall average. Review Query Store's regressed-query information, changed plans, and duration or resource usage compared with the baseline.
At the application layer, monitor timeouts, HTTP 5xx responses, queue length, transaction completion time, and user-facing latency. A query can complete successfully while still violating an application service-level objective.
What to do when a regression appears
Rolling back the entire database immediately may be appropriate during an incident, but it should not automatically become the permanent solution. First determine whether the regression is caused by one query plan, multiple plan changes, stale or unsuitable statistics, data distribution, parameter sensitivity, or an application-side change.
A practical investigation sequence is:
- Compare the previous known-good plan with the plan selected after the change.
- Identify the operator or estimation difference that increased cost.
- Check statistics freshness, index suitability, parameter values, and data distribution.
- Prefer a durable correction in the query, schema, or data-access layer when possible.
- For an urgent and isolated problem, consider Query Store plan forcing or a targeted query hint.
- If the problem is broad or unexplained, temporarily return to the previous level while performing wider testing.
Plan forcing is a transition and containment mechanism, not a substitute for diagnosis. Revalidate a forced plan when data volume, distribution, indexes, or hardware conditions change.
Review database-scoped configurations
Compatibility level is only one database-level control that can influence query behavior. Database-scoped configurations can affect options such as MAXDOP and several query-processing features, depending on the SQL Server version and platform.
Inventory the current overrides with:
SELECT name, value, value_for_secondary, is_value_defaultFROM sys.database_scoped_configurationsORDER BY name;These settings can travel with the database during restore or attach operations. Consequently, a migration checklist should capture database-scoped configurations as well as the compatibility level. An unexpected override can make two apparently identical environments behave differently.
Operational checklist
- Confirm the engine version and supported target compatibility level.
- Record the current compatibility level, Query Store status, and scoped configuration values.
- Build a baseline that represents the real production workload.
- Test the change in staging or a production-like environment.
- Deploy with a documented rollback procedure and an owner for monitoring.
- Compare plans, CPU, duration, I/O, errors, and application latency after the change.
- Investigate query-specific corrections before reverting the entire database.
- Review the results across a normal business cycle, not only the first few minutes.
Conclusion
Changing a SQL Server compatibility level is an important step toward using newer query optimizer behavior and database-engine features. It also introduces the possibility of plan changes and performance regressions. The safest method is to separate the engine migration from the compatibility change, establish a Query Store baseline, deploy the new level deliberately, and handle outliers at the query level whenever practical.
This workflow provides a controlled path to newer SQL Server behavior without forcing the entire application to accept unmeasured changes at once.
0 Comments