Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommend/default settings for ANSI_NULLS and QUOTED_IDENTIFIER [closed]

What is the Recommend/default settings for ANSI_NULLS and QUOTED_IDENTIFIER, should we leave both on?

like image 469
J.W. Avatar asked Jan 11 '23 18:01

J.W.


1 Answers

ANSI_NULLS should always be ON. Always.

Here's why. From the documentation for SET ANSI_NULLS ON:

In a future version of SQL Server, ANSI_NULLS will always be ON and any applications that explicitly set the option to OFF will generate an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

As for QUOTED_IDENTIFIER, that is more of an opinion-based question. I don't really care, because I never set the option explicitly, but if you do use it you should use it consistently everywhere. The reason I don't care is because I never quote identifiers with single or double quotes; I think this is very unreadable and makes them look like string:

SELECT 'alias' = "column" FROM "dbo"."table" AS 'alias';

Really? I much prefer using square brackets, and even then only when required (e.g. the identifier is a reserved word).

SELECT alias = [column] FROM dbo.[table] AS alias;
like image 198
Aaron Bertrand Avatar answered May 13 '23 22:05

Aaron Bertrand