How to check SQL Server Database compatibility after sp_dbcmptlevel is deprecated?

Sql ServerTsqlCompatibility

Sql Server Problem Overview


According to BOL (SQL Server Books Online) on sp_dbcmptlevel,

> This feature will be removed in a future version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible. Use ALTER DATABASE Compatibility Level instead.

Now, the only TSQL way I know of checking database compatibility is through sp_dbcmptlevel. As far as I know, ALTER DATABASE Compatibility Level is just for setting the compatibility level, not getting info.

How should one to get compatibility level without using GUI?

Sql Server Solutions


Solution 1 - Sql Server

select name, compatibility_level , version_name = 
CASE compatibility_level
	WHEN 65  THEN 'SQL Server 6.5'
	WHEN 70  THEN 'SQL Server 7.0'
	WHEN 80  THEN 'SQL Server 2000'
	WHEN 90  THEN 'SQL Server 2005'
	WHEN 100 THEN 'SQL Server 2008/R2'
	WHEN 110 THEN 'SQL Server 2012'
	WHEN 120 THEN 'SQL Server 2014'
    WHEN 130 THEN 'SQL Server 2016'
    WHEN 140 THEN 'SQL Server 2017'
    WHEN 150 THEN 'SQL Server 2019'
    ELSE 'new unknown - '+CONVERT(varchar(10),compatibility_level)
END
from sys.databases

Solution 2 - Sql Server

select compatibility_level from sys.databases where name ='myDB'

Solution 3 - Sql Server

Thought this would be useful here...

65 = SQL Server 6.5
70 = SQL Server 7.0
80 = SQL Server 2000
90 = SQL Server 2005
100 = SQL Server 2008/R2
110 = SQL Server 2012
120 = SQL Server 2014
130 = SQL Server 2016

Solution 4 - Sql Server

How to check SQL Server Database compatibility

   SELECT compatibility_level  as [Current compatibility_level] FROM
     sys.databases WHERE name = 'Database Name';

Solution 5 - Sql Server

I'd like to add the answer from msdn:

USE AdventureWorks2012;
GO
SELECT compatibility_level
FROM sys.databases WHERE name = 'AdventureWorks2012';
GO

https://msdn.microsoft.com/en-us/library/bb933794.aspx

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondance2dieView Question on Stackoverflow
Solution 1 - Sql ServerNick KavadiasView Answer on Stackoverflow
Solution 2 - Sql ServermjvView Answer on Stackoverflow
Solution 3 - Sql Serversam yiView Answer on Stackoverflow
Solution 4 - Sql Serveruser6341745View Answer on Stackoverflow
Solution 5 - Sql ServerJackyView Answer on Stackoverflow