How to view default values of the SET options of a server - sql-server

I read BOL but could not figure it out.
When i exec sp_configure it shows just
Here I can not see if NOCOUNT or ANSI_WARNINGS are SET ON by befault.
How can I do that?
Thanks.

You can see the defaults here:
http://msdn.microsoft.com/en-us/library/ms190707.aspx
You can check your own settings using:
DBCC USEROPTIONS;
And you can check any other session's settings using various columns in sys.dm_exec_sessions.

You have to enable "show advanced options" and run RECONFIGURE
The server defaults are all zero (nothing set) by the way. Your client or driver sets options automatically that will override any server defaults you set
See this for more: Who do ##OPTIONS and sp_configure provide different output?

Related

##OPTIONS bit mask versus DISABLE_DEF_CNST_CHK

We're trying to diagnose some performance issues on both SQL Server 2008 and SQL Server 2008 R2 arising from bad query plans that get cached on behalf of users but are unable to exactly reproduce them in SSMS as we cannot convince SQL Server to match the application's set_options value of 255 that gets returned from sys.dm_exec_plan_attributes, aka. ##OPTIONS.
The ##OPTIONS bit mask is documented at the following MSDN page:
Configure the user options Server Configuration Option
According to the above page the following combination of SET statements should yield an ##OPTIONS value of 255:
SET DISABLE_DEF_CNST_CHK ON
SET IMPLICIT_TRANSACTIONS ON
SET CURSOR_CLOSE_ON_COMMIT ON
SET ANSI_WARNINGS ON
SET ANSI_PADDING ON
SET ANSI_NULLS ON
SET ARITHABORT ON
SET ARITHIGNORE ON
SET QUOTED_IDENTIFIER OFF
SET NOCOUNT OFF
SET ANSI_NULL_DFLT_ON OFF
SET ANSI_NULL_DFLT_OFF OFF
SET CONCAT_NULL_YIELDS_NULL OFF
SET NUMERIC_ROUNDABORT OFF
SET XACT_ABORT OFF
But when you exec that you get the warning:
Line 1: The option 'DISABLE_DEF_CNST_CHK' is obsolete and has no effect.
And PRINT ##OPTIONS returns 254 instead of 255.
Clearly Connection Pooling is able to sort this out when you see EXEC sp_reset_connection in SQL Profiler, as none of our application code actually changes any SET options. But of course we can't call sp_reset_connection from SSMS:
Msg 208, Level 16, State 9, Procedure sp_reset_connection, Line 1
Invalid object name 'sp_reset_connection'.
Is there a trick to get that last DISABLE_DEF_CNST_CHK bit into play? An alternative option name or a system table to tweak?
Well I've found one way to SET DISABLE_DEF_CNST_CHK ON but I DO NOT recommend doing this on a production server...
When new connections are established SQL Server sets ##OPTIONS to the value stored against the 'user options' row in the sys.configurations view. This value defaults to 0. You can check the configured and running value with:
select * from sys.configurations where name = 'user options'
-- or:
EXEC sp_configure 'user options'
As a user with the sysadmin or serveradmin role you can change the value for future connections with:
EXEC sp_configure 'user options', 1
GO
RECONFIGURE
GO
Note that changing this setting affects all future connections to the server which is why I DO NOT recommend doing this on a production server.
After changing this configuration value, then opening a new connection in SSMS, using the other SET options as described in the original question finally got us to ##OPTIONS 255.

DBCC USEROPTIONS server/client

We are using MS SQL server 10.0, and running the DBCC options in two different user accounts, we get two different results. One has language us_english other as british. Where is the information stored on the server, is it possible to change it?
textsize 2147483647
language us_english
dateformat mdy
datefirst 7
lock_timeout -1
quoted_identifier SET
arithabort SET
ansi_null_dflt_on SET
ansi_warnings SET
ansi_padding SET
ansi_nulls SET
concat_null_yields_null SET
isolation level read committed snapshot
In a word, yes. This setting is set on the login that the connection is using and changes all sorts of subtle behavior. Dates are especially affected (first day of the week etc).
To view the default language settings for all logins run the following:
SELECT name, sp.default_language_name FROM master.sys.server_principals AS sp
That will show you the differences.
If you want to change the default language of a login use the following syntax:
ALTER LOGIN LoginName WITH DEFAULT_LANGUAGE = us_english
It looks like the default language for some users is different. You can change the default language for a user with the following syntax:
ALTER USER UserName WITH DEFAULT_LANGUAGE = us_english;
For more info see here.

Enabling CLR Integration on SQL Server 2008-r2

Looking for Enabling CLR Integration I found this document: http://msdn.microsoft.com/en-us/library/ms131048.aspx that said to use the following code for setting to 1 the "crl enabled" variable.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
I want know If a reboot of SQL Server is required? Or, more generaly, what are the steps to follow in order to Enable CRL Integration?
If you use with override option, then restart is not required.
EXEC sp_CONFIGURE 'show advanced options' , '1';
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_CONFIGURE 'clr enabled' , '1'
GO
RECONFIGURE WITH OVERRIDE
GO
The accepted answer is incorrect. The WITH OVERRIDE option of RECONFIGURE has absolutely nothing to do with whether or not a restart of SQL Server is required. The MSDN documentation for RECONFIGURE states that WITH OVERRIDE:
Disables the configuration value checking (for values that are not valid or for nonrecommended values)...
The fact is, no restart of the SQL Server service is required when enabling, or disabling, the "CLR Integration" option in sp_configure. A simple test (run on SQL Server 2008 R2, but works the same across all versions that support SQLCLR) proves this:
EXEC sp_configure 'clr enabled'; -- show current value
EXEC sp_configure 'clr enabled', 0; RECONFIGURE;
EXEC sp_configure 'clr enabled'; -- show current value
GO
EXEC sp_configure 'clr enabled'; -- show current value
EXEC sp_configure 'clr enabled', 1; RECONFIGURE;
EXEC sp_configure 'clr enabled'; -- show current value
GO
Results:
Pay attention to the run_value field. It starts out as "1" since "CLR Integration" is already enabled on my system. But it switches with only calling RECONFIGURE.
name minimum maximum config_value run_value
clr enabled 0 1 1 1
clr enabled 0 1 0 0
clr enabled 0 1 0 0
clr enabled 0 1 1 1
Additionally, it should be stated with regards to the initial code shown in the Question, the statement for
sp_configure 'show advanced options', 1;
is unnecessary since clr enabled is not an advanced option.
To prove the point about clr enabled not being an advanced option, and even showing another way to prove that this option does not require a reboot, just execute the following simple query:
SELECT [name], [value], [value_in_use], [is_dynamic], [is_advanced]
FROM sys.configurations
WHERE [configuration_id] = 1562;
/*
name value value_in_use is_dynamic is_advanced
clr enabled 1 1 1 0
*/
As you can see in the result set shown above, is_advanced is 0, meaning "not an advanced option (yes, the official Microsoft documentation is currently incorrect; I will update it when I have time). Also, is_dynamic is 1, meaning that simply executing RECONFIGURE will enable the option immediately, not requiring a restart of the instance.
To summarize: The sum total of all steps required to enable "CLR Integration", and without needing to restart the SQL Server service, are as follows:
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
That's it. **
** WOW64 servers will require a restart of the server in order for this option to take effect. ( clr enabled Server Configuration Option )

Set UK date format for SQL Express

How do I permanently set the date format for SQL Express to be UK format (dd/mm/yyyy).
I know I can use SET DATEFORMAT DMY, but this only works for that connection.
I have also seen,
exec sp_addlanguage 'British', 'English', 'January,February,March,April,May,June,July,August,September,October, November,December',
'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec', 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday'
,dmy,1
sp_configure 'default language', 1
reconfigure with override
but, this doesn't seem to work with SQL Express (I get, Could not find stored procedure 'sp_addlanguage'.).
Cheers
You have to set language using sp_configure
EXEC sp_configure 'default language', '23' -- british_english ?
GO
RECONFIGURE;
Edit: need to use code from sys.syslanguages as mentioned
However, default langauge will also need changed for all logins. Hence ##langage showing us_english.

Set NOCOUNT OFF at database level?

Can I set NOCOUNT to be OFF by default for a particular database?
I need it for NHibernate (if it's ON, I get exceptions when saving). I can see the setting to disable it for an entire server (where it's set ON), but we're sharing the server with other databases. Is there a way I can set it to OFF just for my database?
Or is there an NHibernate setting that will do this for me? (I've worked around it for now with a custom DriverConnectionProvider that issues the command whenever it creates a connection. Works ok, but feels a bit awkward)
I'm using SQL Server 2000, btw.
Thanks
Matt
no, there is no database wide setting for SET NOCOUNT.
same question: http://www.eggheadcafe.com/software/aspnet/32120672/set-nocount.aspx
You could use the NH IInterceptor interface's OnPrepareStatement method to modify the NH-generated SQL statements to include a "set nocount off" statement at the top of every sql query issued by your application.
Some bloke called Dave reckons it's "evil" to do so, but it might be your answer. The link takes you to the page on his blog describing how to implement it.
My reservation about doing so is you would be creating a dependency on your application running against a database server that understands "set nocount off" - in other words, you'd be ignoring the configured dialect.
You can set nocount property of database ON/OFF from SSMS as well. Please find below
Right click on instance and select properties
Then select Connections
On right pane, you will find list of properties including 'no count'
Uncheck this property to make it OFF
Set NOCOUNT is Set at DB level. Execute below queries one after another separately. This gives better idea.
SET NOCOUNT ON
Update Users set FirstName='XXXX' where Id='YYYY';
***Command(s) completed successfully.
SET NOCOUNT OFF
Update Users set FirstName='XXXX' where Id='YYYY';
***(1 row(s) affected)

Resources