查看或更改数据库的兼容级别View or Change the Compatibility Level of a Database
适用于:Applies to: SQL ServerSQL Server(所有支持的版本)
SQL ServerSQL Server (all supported versions)
Azure SQL 数据库Azure SQL Database
Azure SQL 数据库Azure SQL Database
SQL ServerSQL Server(所有支持的版本)
SQL ServerSQL Server (all supported versions)
Azure SQL 数据库Azure SQL Database
Azure SQL 数据库Azure SQL Database
本主题说明如何使用 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 或 SQL Server Management StudioSQL Server Management Studio 在 Transact-SQLTransact-SQL中查看或更改数据库的兼容级别。This topic describes how to view or change the compatibility level of a database in SQL Server 2019 (15.x)SQL Server 2019 (15.x) by using SQL Server Management StudioSQL Server Management Studio or Transact-SQLTransact-SQL. 在更改数据库的兼容级别之前,应先了解此更改对应用程序的影响。Before you change the compatibility level of a database, you should understand the impact of the change on your applications. 有关详细信息,请参阅 ALTER DATABASE 兼容级别 (Transact-SQL)。For more information, see ALTER DATABASE Compatibility Level (Transact-SQL).
本主题内容In This Topic
开始之前:Before you begin:
查看或更改数据库的兼容级别,使用:To view or change the compatibility level of a database, using:
开始之前Before You Begin
SecuritySecurity
权限Permissions
需要对数据库拥有 ALTER 权限。Requires ALTER permission on the database.
使用 SQL Server Management StudioUsing SQL Server Management Studio
查看或更改数据库的兼容级别To view or change the compatibility level of a database
连接到 SQL Server 数据库引擎SQL Server Database Engine的相应实例之后,在对象资源管理器中,单击服务器名称。After connecting to the appropriate instance of the SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, click the server name.
展开 “数据库” ,然后根据数据库的不同,选择用户数据库,或展开 “系统数据库” ,再选择系统数据库。Expand Databases, and, depending on the database, either select a user database or expand System Databases and select a system database.
右键单击数据库,再单击“属性”。Right-click the database, and then click Properties.
“数据库属性” 对话框将打开。The Database Properties dialog box opens.
在 “选择页” 窗格中,单击 “选项” 。In the Select a page pane, click Options.
当前兼容级别显示在 “兼容级别” 列表框中。The current compatibility level is displayed in the Compatibility level list box.
若要更改兼容级别,请从列表中选择其他选项。To change the compatibility level, select a different option from the list. ALTER DATABASE 兼容性级别 (Transact-SQL) 页中列出了不同 数据库引擎Database Engine 版本的可用选项。The available options for different 数据库引擎Database Engine versions are listed in the ALTER DATABASE Compatibility Level (Transact-SQL) page.
使用 Transact-SQLUsing Transact-SQL
查看数据库的兼容级别To view the compatibility level of a database
连接到 数据库引擎Database Engine。Connect to the 数据库引擎Database Engine.
在标准菜单栏上,单击 “新建查询” 。From the Standard bar, click New Query.
将以下示例复制并粘贴到查询窗口中,然后单击“执行” 。Copy and paste the following example into the query window and click Execute. 此示例将返回 AdventureWorks2012AdventureWorks2012 数据库的兼容级别。This example returns the compatibility level of the AdventureWorks2012AdventureWorks2012 database.
USE AdventureWorks2012;
GO
SELECT compatibility_level
FROM sys.databases WHERE name = 'AdventureWorks2012';
GO
更改数据库的兼容级别To change the compatibility level of a database
连接到 数据库引擎Database Engine。Connect to the 数据库引擎Database Engine.
在标准菜单栏上,单击 “新建查询” 。From the Standard bar, click New Query.
将以下示例复制并粘贴到查询窗口中,然后单击“执行” 。Copy and paste the following example into the query window and click Execute. 此示例将 AdventureWorks2012AdventureWorks2012 数据库的兼容级别更改为
120
,这是 SQL Server 2014 (12.x)SQL Server 2014 (12.x) 的兼容级别。This example changes the compatibility level of the AdventureWorks2012AdventureWorks2012 database to120
, which is the compatibility level for SQL Server 2014 (12.x)SQL Server 2014 (12.x).
ALTER DATABASE AdventureWorks2012
SET COMPATIBILITY_LEVEL = 120;
GO
另请参阅See Also
ALTER DATABASE (Transact-SQL) 兼容性级别ALTER DATABASE (Transact-SQL) Compatibility Level