SET ARITHIGNORE (Transact-SQL)SET ARITHIGNORE (Transact-SQL)

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

控制查询期间是否返回溢出或被零除错误的错误消息。Controls whether error messages are returned from overflow or divide-by-zero errors during a query.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

-- Syntax for SQL Server and Azure SQL Database

SET ARITHIGNORE { ON | OFF }
-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse  

SET ARITHIGNORE OFF

备注

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.

备注

Azure Synapse Analytics 中的无服务器 SQL 池不支持此语法。This syntax is not supported by serverless SQL pool in Azure Synapse Analytics.

备注Remarks

SET ARITHIGNORE 设置只控制是否返回错误消息。The SET ARITHIGNORE setting only controls whether an error message is returned. SQL ServerSQL Server 在计算中出现溢出或被零除错误时将返回 NULL,不考虑此设置。returns a NULL in a calculation involving an overflow or divide-by-zero error, regardless of this setting. 可以使用 SET ARITHABORT 设置来确定是否终止查询。The SET ARITHABORT setting can be used to determine whether the query is terminated. 此设置不影响 INSERT、UPDATE 和 DELETE 语句执行过程中发生的错误。This setting does not affect errors occurring during INSERT, UPDATE, and DELETE statements.

如果 SET ARITHABORT 或 SET ARITHIGNORE 为 OFF,而 SET ANSI_WARNINGS 为 ON,则遇到被零除或溢出错误时,SQL ServerSQL Server 仍会返回错误消息。If either SET ARITHABORT or SET ARITHIGNORE is OFF and SET ANSI_WARNINGS is ON, SQL ServerSQL Server still returns an error message when encountering divide-by-zero or overflow errors.

SET ARITHIGNORE 设置是在执行或运行时设置的,而不是在分析时设置的。The setting of SET ARITHIGNORE is set at execute or run time and not at parse time.

要查看此设置的当前设置,请运行以下查询。To view the current setting for this setting, run the following query.

DECLARE @ARITHIGNORE VARCHAR(3) = 'OFF';  
IF ( (128 & @@OPTIONS) = 128 ) SET @ARITHIGNORE = 'ON';  
SELECT @ARITHIGNORE AS ARITHIGNORE;  

权限Permissions

要求具有 public 角色的成员身份。Requires membership in the public role.

示例Examples

以下示例说明将两种 SET ARITHIGNORE 设置用于两类查询错误的情况。The following example demonstrates using both SET ARITHIGNORE settings with both types of query errors.

SET ARITHABORT OFF;  
SET ANSI_WARNINGS OFF  
GO  
  
PRINT 'Setting ARITHIGNORE ON';  
GO  
-- SET ARITHIGNORE ON and testing.  
SET ARITHIGNORE ON;  
GO  
SELECT 1 / 0 AS DivideByZero;  
GO  
SELECT CAST(256 AS TINYINT) AS Overflow;  
GO  
  
PRINT 'Setting ARITHIGNORE OFF';  
GO  
-- SET ARITHIGNORE OFF and testing.  
SET ARITHIGNORE OFF;  
GO  
SELECT 1 / 0 AS DivideByZero;  
GO  
SELECT CAST(256 AS TINYINT) AS Overflow;  
GO  

示例:Azure Synapse AnalyticsAzure Synapse Analytics并行数据仓库Parallel Data WarehouseExamples: Azure Synapse AnalyticsAzure Synapse Analytics and 并行数据仓库Parallel Data Warehouse

以下示例演示了被零除错误和溢出错误。The following example demonstrates the divide by zero and the overflow errors. 对于这些错误,该示例不返回错误消息,因为 ARITHIGNORE 为 OFF。This example does not return an error message for these errors because ARITHIGNORE is OFF.

-- SET ARITHIGNORE OFF and testing.  
SET ARITHIGNORE OFF;  
SELECT 1 / 0 AS DivideByZero;  
SELECT CAST(256 AS TINYINT) AS Overflow;  

另请参阅See Also

SET 语句 (Transact-SQL) SET Statements (Transact-SQL)
SET ARITHABORT (Transact-SQL)SET ARITHABORT (Transact-SQL)