page contents

About the Post

Author Information

SQL Server Compatibility Levels

Have you ever wondered what versions of SQL Server related to the compatibility levels? This article will show you the levels and also how to change existing databases to different SQL releases.

This is a list of all SQL Server Compatibility Levels:

Product

Database Engine Version

Compatibility Level Designation

Supported Compatibility Level Values

SQL Server vNext 14 140 140, 130, 120, 110, 100
SQL Server 2016 13 130 130, 120, 110, 100
SQL Database 12 120 130, 120, 110, 100
SQL Server 2014 12 120 120, 110, 100
SQL Server 2012 11 110 110, 100, 90
SQL Server 2008 R2 10.5 105 100, 90, 80
SQL Server 2008 10 100 100, 90, 80
SQL Server 2005 9 90 90, 80
SQL Server 2000 8 80 80

Note: Azure SQL Database V12 was released in December 2014. One aspect of that release was that newly created databases had their compatibility level set to 120. In 2015 SQL Database began support for level 130, although the default remained 120.

Starting in mid-June 2016, in Azure SQL Database, the default compatibility level will be 130 instead of 120 for newly created databases. Existing databases created before mid-June 2016 will not be affected, and will maintain their current compatibility level (100, 110, or 120).

If you want level 130 for your database generally, but you have reason to prefer the level 110 cardinality estimation algorithm, see ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL), and in particular its keyword LEGACY_CARDINALITY_ESTIMATION =ON.

For details about how to assess the performance differences of your most important queries, between two compatibility levels on Azure SQL Database, see Improved Query Performance with Compatibility Level 130 in Azure SQL Database.

You can change the level by issuing these commands to check/change the following:

  1. Determine Database Engine version
  2. Current database compatibility level
  3. Change the database compatibility level

Execute the following query to determine the version of the Database Engine that you are connected to.

SELECT SERVERPROPERTY(‘ProductVersion’);

SELECT SERVERPROPERTY('ProductVersion');

Now, you can either check a single database compatibility level:

USE AdventureWorks2012;

GO

SELECT compatibility_level

FROM sys.databases WHERE name ‘AdventureWorks2012’;

GO

USE AdventureWorks2012;

GO

SELECT compatibility_level

FROM sys.databases WHERE name = 'AdventureWorks2012';

GO


Or you can check all of the databases compatibility levels at once:

SELECT namecompatibility_level FROM sys.databases;

SELECT name, compatibility_level FROM sys.databases;

As you can tell from my results, I will not be able to change the compatibility level of any database to any of the newer releases SQL Server, like 2014 or 2016. I am using SQL Server 2012 on this instance.

Note: Before proceeding, please check the Reference Microsoft article: ALTER DATABASE Compatibility Level (Transact-SQL) to see the differences between compatibility levels and also ensure you follow best practices.

This syntax (example) will allow me to change the compatibility level:
ALTER DATABASE database_name

SET COMPATIBILITY_LEVEL { 140 | 130 | 120 | 110 | 100 | 90 }

This command will allow me to downgrade to SQL Server 2008:

ALTER DATABASE AdventureWorks2012

SET COMPATIBILITY_LEVEL = 100

ALTER DATABASE AdventureWorks2012

SET COMPATIBILITY_LEVEL = 100

As usual, I hope this information helps you J

Tags: , , , , , , , , , ,

No comments yet.

Leave a Reply

Copy Protected by Chetan's WP-Copyprotect.