rspec/rules/S6498/tsql/rule.adoc

57 lines
1.8 KiB
Plaintext

== Why is this an issue?
Disabling "ANSI_WARNINGS" and/or "ARITHABORT" in a procedure may silence errors, decrease performance, or block index creation.
:link-with-uscores1: https://learn.microsoft.com/en-us/sql/t-sql/statements/set-arithabort-transact-sql
:link-with-uscores2: https://learn.microsoft.com/en-us/sql/t-sql/statements/set-ansi-warnings-transact-sql
From the documentation ({link-with-uscores1}[ARITHABORT], {link-with-uscores2}[ANSI_WARNINGS]), disabling these options could result in (among others):
``++SET ANSI_WARNINGS OFF++``
* CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail
* No warning issued if null values appear in aggregate functions, such as SUM, AVG, MAX, MIN, STDEV, STDEVP, VAR, VARP, or COUNT
* The divide-by-zero and arithmetic overflow errors cause null values to be returned, no roll-back
``++SET ARITHABORT OFF++``
* It can negatively impact query optimization, leading to performance issues
* An arithmetic, overflow, divide-by-zero, or domain error, during INSERT, UPDATE, or DELETE statement will cause SQL Server to insert or update a NULL value
This rule raises an issue when "ANSI_WARNINGS" and/or "ARITHABORT" are set to ``++OFF++`` in a procedure.
=== Noncompliant code example
[source,sql]
----
CREATE PROCEDURE myProc
AS
BEGIN
SET ANSI_WARNINGS OFF; -- Noncompliant
SET ARITHABORT OFF; -- Noncompliant
-- ...
END
----
=== Compliant solution
[source,sql]
----
CREATE PROCEDURE myProc
AS
BEGIN
-- OK - Default value is ON
END
CREATE PROCEDURE myProc
AS
BEGIN
SET ANSI_WARNINGS, ARITHABORT ON;
END
----
== Resources
* {link-with-uscores1}[Microsoft Documentation: SET ARITHABORT (Transact-SQL)]
* {link-with-uscores2}[Microsoft Documentation: SET ANSI_WARNINGS (Transact-SQL)]