根据sp_dbcmptlevel
上的BOL(SQL Server Books Online),
将在Microsoft SQL Server的未来版本中删除此功能。请勿在新的开发工作中使用此功能,并尽快修改当前使用此功能的应用程序。请改用ALTER DATABASE兼容级别。
现在,我知道检查数据库兼容性的唯一TSQL方式是通过sp_dbcmptlevel
。据我所知,ALTER DATABASE Compatibility Level
仅用于设置兼容级别,而不是获取信息。
如何在不使用GUI的情况下获得兼容级别?
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
select compatibility_level from sys.databases where name ='myDB'
认为这在这里很有用......
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
我想添加msdn的答案:
USE AdventureWorks2012;
GO
SELECT compatibility_level
FROM sys.databases WHERE name = 'AdventureWorks2012';
GO
如何检查SQL Server数据库兼容性
SELECT compatibility_level as [Current compatibility_level] FROM sys.databases WHERE name = 'Database Name';