views:

168

answers:

1

Guys,

Quick Questions...

Where are the values for SET OPTIONS stored in the database for a SP, Func, Trigger, etc? If they are different from the global settings?

SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET NUMERIC_ROUNDABORT OFF

I know the global settings for a database are stored in sys.databases view. But what about for each Stored Proc or other objects.

USE [SomeDB]
GO

SET ARITHABORT OFF
SET CONCAT_NULL_YIELDS_NULL OFF
SET QUOTED_IDENTIFIER OFF
GO

CREATE usp_SampleProc
AS
BEGIN
-- perform some action
END

I see that a couple could be retrived using:

SELECT OBJECTPROPERTY(OBJECT_ID('Procedure_Name'), 'ExecIsQuotedIdentOn')
SELECT OBJECTPROPERTY(OBJECT_ID('Procedure_Name'), 'ExecIsAnsiNullsOn')

where are the rest... are they even stored for each Stored Proc.....at all?
thanks,
_Ub

+2  A: 

Those that apply to procedures, like ANSI_NULLS and QUOTED_IDENTIFIER are in sys.sql_modules, where they are retrieved from by OBJECTPROPERTY.

Those that apply to databases and are set per database are available in sys.databases.

Those that apply to sessions are available in sys.dm_exec_sessions.

In the end what actualy gets applied depends from setting to setting, and the rules of overwrites and defaults are complex to say the least. Some client drivers set options on/off automatically. Not the same options and not the same defaults, depends from client to client (ODBC, OleDB, SNAC, SqlClient etc). The generic rule is:

  1. A database option overrides an instance option.
  2. A SET option overrides a database option.
  3. A hint overrides a SET option.
Remus Rusanu
thanks for the quick response, but it only has uses_quoted_identifier is_schema_bound uses_database_collation is_recompiled ... what about the rest._Ub
UB
what about SET ARITHABORT ONSET ANSI_WARNINGS ONfor a particular procedure.these two are what I am more concerned about?
UB
Only QUOTED_IDENTIFER and ANSI_NULLS settings are captured at procedure creation time. All other settings, the current session value will apply.
Remus Rusanu
I agree. That's my understanding as of now. But I am trying to get more info on the rules how the SET OPTIONS are applied when there are multiple conflicting OPTIONS. What I want to know is, if I specify the SET OPTIONS inside (like SET NOCOUNT ON) the stored Proc (and during the creation of the Stored Proc.) will it override SET OPTIONS from the client (JDBC).
UB
Is basically a stack of sesttings. The session has a current state (from instance/database/explicit SETs). When the procedure is executed, the session state is copied and pushed, then the two captured settings are applied (QUOTED_IDENTIFIER and ANSI_NULLS). Wehn something like SET NOCOUNT ON is in the procedure, it will take effect at execution time. As such it change the session setting for the scope of the procedure execution. When the procedure terminates, the old sessions settings are popped back.
Remus Rusanu
Sounds good. Thanks for the responses.
UB
SET QUOTED IDENTIFIER can not be set at run time inside the stored proc from (http://msdn.microsoft.com/en-us/library/ms174393%28SQL.90%29.aspx and http://stackoverflow.com/questions/1137821/problem-with-set-quoted-identifier)When executed inside a stored procedure, the setting of SET QUOTED_IDENTIFIER is not changed (thanks gbn pointing this out)
Ramesh Vel
Thanks Ramesh. Is there an MSDN article that shows what could be set at runtime. My concern is more about SET ARITHABORT ON SET ANSI_WARNINGS ON
UB