What's the recommended configuration regarding ANSI relating settings?

2.5k views Asked by At

I've seen many questions regarding the ANSI related settings, and read some docs that state some features (like indexes on computed columns and indexed views) can become worthless depending on ANSI settings on or off... So, what the recommended values for those:

  • ANSI_Padding
  • ANSI_NULLS
  • ANSI_WARNINGS
  • Concat_NULL_YELDS_NULL
  • QUOTED_IDENTIFIER
  • ARITHABORT
  • NUMERIC_ROUNDABORT

I would like guidelines regarding those.

1

There are 1 answers

1
Martin Smith On BEST ANSWER

For indexed views and indexed or persisted computed columns the following SET OPTIONS are all prescribed

SET options              Required value
---------------------    -------------
ANSI_NULLS                   ON
ANSI_PADDING                 ON
ANSI_WARNINGS*               ON
ARITHABORT                   ON
CONCAT_NULL_YIELDS_NULL      ON
NUMERIC_ROUNDABORT           OFF
QUOTED_IDENTIFIER            ON

In SQL Server 2005 setting ANSI_WARNINGS to ON implicitly sets ARITHABORT to ON unless the database compatibility level is set to 80 or earlier (when it needs to be set explicitly).

Despite this it does make sense to be consistent in the ARITHABORT setting as this is used as a plan cache key and inconsistency can lead to duplicated plans wasting valuable plan cache space. You can see this from the query below.

SET ARITHABORT OFF
GO

SELECT * FROM master..spt_values WHERE number= -10 /*plan_cache_test*/

GO

SET ARITHABORT ON
GO

SELECT * FROM master..spt_values WHERE number= -10 /*plan_cache_test*/

GO
    SELECT *
    FROM   sys.dm_exec_cached_plans
           CROSS APPLY sys.dm_exec_plan_attributes(plan_handle) AS epa
           CROSS APPLY sys.dm_exec_query_plan(plan_handle)
           CROSS APPLY sys.dm_exec_sql_text(plan_handle)
    WHERE  attribute = 'set_options' AND text LIKE '%plan_cache_test%' 
                                     AND text NOT LIKE '%this_query%'

Even without the indexed view / persisted column requirements the OFF settings are deprecated for the following optionsANSI_PADDING,ANSI_NULLS,CONCAT_NULL_YIELDS_NULL and XQuery and XML data modification statements requires that QUOTED_IDENTIFIER be ON.