Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Gilt für:SQL Server
Azure SQL-Datenbank
Verwaltete Azure SQL-Instanz
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL-Analyseendpunkt in Microsoft Fabric
Lagerhaus in Microsoft Fabric
SQL-Datenbank in Microsoft Fabric
Die Einstellung SET ARITHABORT bestimmt, ob eine Abfrage stoppt, wenn während der Abfrageausführung ein Überlauf- oder Teile-um-Null-Fehler auftritt.
Wenn Sie und
SET ANSI_WARNINGS OFFsetzenSET ARITHABORT ON, führen arithmetische Fehler dazu, dass der Batch endet. Treten die Fehler in einer Transaktion auf, so wird für die Transaktion ein Rollback durchgeführt.Wenn sowohl
SET ARITHABORTals auchSET ANSI_WARNINGSsindOFFund ein rechentechnischer Fehler auftritt, erscheint eine Warnmeldung (sofernSET ARITHIGNOREnicht istON) und das Ergebnis der arithmetischen Operation istNULL.
Transact-SQL-Syntaxkonventionen
Syntax
Syntax for SQL Server, serverless SQL pool in Azure Synapse Analytics, Microsoft Fabric, SQL-Datenbank in Microsoft Fabric
SET ARITHABORT { ON | OFF }
Syntax für Azure Synapse Analytics und Analytics-Plattformsystem (PDW)
SET ARITHABORT ON
Hinweise
Wenn ANSI_WARNINGS dies ist ON (der Standard), hat die Einstellung von ARITHABORT keine funktionale Auswirkung. Rechenfehler führen dazu, dass die Abfrage endet, aber der Batch bricht nicht ab (solange die Einstellung XACT_ABORT ist OFF).
Warnung
Die Standardeinstellung ARITHABORT für SQL Server Management Studio (SSMS) ist ON, während eine Client-Verbindung in einer Anwendung standardmäßig auf ARITHABORT OFFgilt. Selbst wenn es keinen funktionalen Unterschied gibt, solange ANSI_WARNINGS es ist ON, ist die Einstellung ARITHABORT immer noch ein Cache-Schlüssel. Daher haben SSMS und eine Anwendung, die jeweils ihre jeweiligen Standardeinstellungen verwenden, unterschiedliche Cache-Einträge und können unterschiedliche Abfragepläne erhalten, was es schwierig macht, schlecht funktionierende Abfragen zu beheben. Das heißt, dieselbe Abfrage kann in der Anwendung langsamer ausgeführt werden als in SSMS. Wenn Sie mit Management Studio Abfragen beheben, passen Sie immer die Client-Einstellung ARITHABORT an.
Für die Ausdrucksauswertung gilt: Wenn sowohl SET ANSI_WARNINGS und SET ARITHABORT als auch OFF eine INSERT, , oder DELETE Anweisung UPDATEauf einen arithmetischen Überlauf-, Teile-zu-Null- oder Domänenfehler stoßen, fügt die Abfrage einen Wert ein oder aktualisiert sie anNULL. Wenn die Zielspalte keine NULL-Werte zulässt, schlägt das Einfügen oder Aktualisieren fehl, und dem Benutzer wird ein Fehler angezeigt.
Die Einstellung von SET ARITHABORT erfolgt zur Ausführungs- oder Laufzeit und nicht zur Parsezeit.
SET ARITHABORT OFFwird in den dedizierten SQL-Pools von Azure Synapse Analytics nicht unterstützt.
Berechtigungen
Erfordert die Mitgliedschaft in der public -Rolle.
Aktuellen Einstellungen von ARITHABORT
Um die aktuelle Einstellung für SET ARITHABORTanzuzeigen, führen Sie folgende T-SQL-Abfrage aus:
DECLARE @ARITHABORT VARCHAR(3) = 'OFF';
IF ( (64 & @@OPTIONS) = 64 ) SET @ARITHABORT = 'ON';
SELECT @ARITHABORT AS ARITHABORT;
Beispiele
Das folgende Beispiel zeigt die Teile-durch-Null- und Überlauffehler bei verschiedenen SET ARITHABORT Einstellungen.
- Das Skript erstellt Beispieltabellen
t1undt2fügt Beispieldatenwerte ein. - Setze
ANSI_WARNINGS ONund führe Tests aus, um das Standardverhalten eines Dividation-by-Zero-Fehlers und eines arithmetischen Überlaufs zu sehen. - Setze
ANSI_WARNINGS OFFso, dass EffektARITHABORThat, und setzeARITHABORT ON. Führen Sie Tests durch, um das Verhalten mit einem Teile-um-Null-Fehler und einem arithmetischen Überlauf zu sehen. - Setze sowohl
ANSI_WARNINGS OFFals auchARITHABORT OFF. Führen Sie Tests durch, um das Verhalten mit einem Teile-um-Null-Fehler und einem arithmetischen Überlauf zu sehen. - Räumen Sie die Mustertabellen auf.
-- SET ARITHABORT
-------------------------------------------------------------------------------
-- Create tables t1 and t2 and insert data values.
CREATE TABLE t1 (
a TINYINT,
b TINYINT
);
CREATE TABLE t2 (
a TINYINT NOT NULL
);
GO
INSERT INTO t1
VALUES (1, 0);
INSERT INTO t1
VALUES (255, 1);
GO
-- First run with ANSI_WARNINGS ON to see the default behavior.
PRINT '*** SET ANSI_WARNINGS ON';
SET ANSI_WARNINGS ON;
SET XACT_ABORT OFF; -- To make sure that we have the default setting for this option.
GO
PRINT '*** Testing divide-by-zero during SELECT';
GO
SELECT a / b AS ab
FROM t1;
PRINT 'This prints, despite the error message.';
GO
PRINT '*** Testing divide-by-zero during INSERT';
GO
INSERT INTO t2
SELECT a / b AS ab
FROM t1;
PRINT 'This prints, despite the error message.';
GO
PRINT '*** Testing tinyint overflow';
GO
INSERT INTO t2
SELECT a + b AS ab
FROM t1;
PRINT 'This prints, despite the error message.';
GO
PRINT '*** Resulting data - should be no data';
GO
SELECT *
FROM t2;
GO
-- Truncate table t2.
TRUNCATE TABLE t2;
GO
-- Set ANSI_WARNINGS OFF so that ARITHABORT has effect, and set ARITHABORT ON.
PRINT '*** SET ANSI_WARNINGS OFF; SET ARITHABORT ON';
GO
SET ANSI_WARNINGS OFF;
SET ARITHABORT ON;
GO
PRINT '*** Testing divide-by-zero during SELECT';
GO
SELECT a / b AS ab
FROM t1;
PRINT 'This does not print.';
GO
PRINT '*** Testing divide-by-zero during INSERT';
GO
INSERT INTO t2
SELECT a / b AS ab
FROM t1;
PRINT 'This does not print.';
GO
PRINT '*** Testing tinyint overflow';
GO
INSERT INTO t2
SELECT a + b AS ab
FROM t1;
PRINT 'This does not print.';
GO
PRINT '*** Resulting data - should be 0 rows';
GO
SELECT *
FROM t2;
GO
-- Truncate table t2.
TRUNCATE TABLE t2;
GO
-- Set both ANSI_WARNINGS OFF and ARITHABORT OFF.
PRINT '*** SET ARITHABORT OFF';
GO
SET ARITHABORT OFF;
GO
PRINT '*** Testing divide-by-zero during SELECT';
GO
-- Returns NULL.
SELECT a / b AS ab
FROM t1;
GO
PRINT '*** Testing divide-by-zero during INSERT';
GO
-- Fails with NOT NULL violation.
INSERT INTO t2
SELECT a / b AS ab
FROM t1;
GO
PRINT '*** Testing tinyint overflow';
GO
-- Fails with NOT NULL violation
INSERT INTO t2
SELECT a + b AS ab
FROM t1;
GO
PRINT '*** Resulting data - should be 0 rows';
GO
SELECT *
FROM t2;
GO
-- Drop tables t1 and t2 and restore ANSI_WARNINGS
DROP TABLE t1;
DROP TABLE t2;
SET ANSI_WARNINGS ON
GO