Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop SQL Server Management Studio from adding ANSI_NULLS and QUOTED_IDENTIFIER

How do I prevent SQL Management Studio (10.50.2500.0) from adding this to the beginning of every stored procedure when I right-click/Modify?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Neither of these settings are useful to me. ANSI_NULLS ON and QUOTED_IDENTIFIER ON is set on all my servers, DBs and connections I make. Besides that, I never use double quotes (I used brackets for reserved words) and all my nullable fields I properly use IS NULL when needed.

I delete the settings every time I edit a procedure. All my procedures properly have them set and that will never change in my environment. Verified by:

SELECT uses_ansi_nulls, uses_quoted_identifier
FROM sys.sql_modules
WHERE object_id = object_id( 'proc_name' )
like image 233
ThinkingStiff Avatar asked Dec 09 '11 00:12

ThinkingStiff


1 Answers

Not sure whether this counts as an answer or an unhelpful non-answer, but as Damien_The_Unbeliever suggested you absolutely don't want SSMS to stop scripting these lines. Because they are in the sql_modules table they form an integral part of the definition of the stored procedure, along with the SQL code itself. So they can't be "turned off" any more than your SQL code could.

If you create/alter a stored procedure from a connection that has a different ANSI_NULLS option value to that used when the stored procedure was created/defined, then you change the behaviour of that stored procedure, permanently!

It is for this reason that SSMS (and any half-decent SQL object scripting tool) will always output these lines - because if you remove them or change them, you are changing the definition of the stored procedure (removing them, particularly, is bad because it means that the behaviour of the stored procedure, depending on what connection it is published from, can vary).

Doing a quick google search for "ANSI_NULLS QUOTED_IDENTIFIER stored procedure", the top result is the following article that seems to explain the options, and their impact, very clearly: http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/

like image 91
Tao Avatar answered Oct 04 '22 20:10

Tao