Configuring SQL ServerIN THIS CHAPTER Making sense of SQL Server configuration Configuring the server-level configuration options Configuring the database-level configuration options Con
Trang 1Nielsen p06.tex V4 - 07/21/2009 2:19pm Page 882
Trang 2Configuring SQL Server
IN THIS CHAPTER Making sense of SQL Server configuration
Configuring the server-level configuration options Configuring the database-level configuration options
Configuring the connection-level options
SQL Server has a plethora of configuration options The difficulty in
master-ing them lies in the fact that they are spread across three levels:
■ Server-level options generally configure how the server works with
hardware, and determine the database defaults
■ Database-level options determine the behavior of the database, and set
the connection-level defaults
■ Connection-level options determine the current behaviors within the
connection or current procedure
Several of the configuration options overlap or simply set the default for the
level immediately below This chapter pulls these three configuration levels into
a single unified understanding of how they relate to and affect each other This
chapter does not cover every single SQL Server configuration option but it covers
most of them that I think are important If you are a SQL Server beginner, you
may find that some of the configuration options are advanced and you may not
need them immediately
Setting the Options
Whether you choose to adjust the properties from SQL Server Management
Studio’s graphical tool or from code is completely up to you, but not every
property is available from Management Studio using the graphical interface
While the graphical interface has the advantage of being easy to use, and walks
you through easily understood dialogs that prompt for the possible options in
a pick-and-choose format, it lacks the repeatability of a T-SQL script run as a
query
To view miscellaneous information about the com-puter system while configuring SQL Server, query the
sys.dm_os_sys_info dynamic management view.
Trang 3Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 884
Part VI Enterprise Data Management
New in SQL Server 2008 Configuration
SQL Server 2008 offers many new configuration options, such as backup compression default
and filestream access level, that give the SQL DBA much more control in configuring SQL
Server 2008
The configuration options set working set size, open objects, and locks are still present in the
sp_configure stored procedure, but their functionality is unavailable in SQL Server 2008 These options
have no effect
Configuring the server
The server-level configuration options control server-wide settings, such as how SQL Server interacts
with hardware, how it multi-threads within Windows, and whether triggers are permitted to fire other
triggers When configuring the server, keep in mind the goals of configuration: consistency and
perfor-mance
Graphically, many of the server options may be configured within the Server Properties page, which you
can open by right-clicking a server in the console tree and choosing Properties from the context menu
The General tab in Management Studio’s SQL Server Properties dialog (see Figure 39-1) reports the
ver-sions and environment of the server
The same information is available to code For example, the version may be identified with the
@@VERSIONglobal variable:
select @@VERSION;
Result:
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34 Copyright (c) 1988-2008 Microsoft Corporation Enterprise Edition on Windows NT 5.2 <X86> (Build 3790: Service Pack 2)
The first line of the preceding result includes the product version of SQL Server In this example, the
SQL Server product version is 10.0.1600.22 The last line of the result can be confusing It reports the
edition of SQL Server In this example, it is SQL Server 2008 Enterprise Edition, but the service pack
reported in the last line is the Windows service pack level and not the SQL Server service pack level
In this example, it is SP2 for Windows Server 2003 That is one of the reasons why I don’t like to use
theSELECT @@VERSIONcommand Instead, I prefer to use theSERVERPROPERTYsystem function to
determine the information The advantage of this method is that the function may be used as an
expres-sion within aSELECTstatement The following example uses theSERVERPROPERTYfunction to return
the SQL Server product version, product level, and edition:
SELECT SERVERPROPERTY(’ProductVersion’) AS ProductVersion, SERVERPROPERTY(’ProductLevel’) AS ProductLevel, SERVERPROPERTY(’Edition’) AS Edition;
Trang 4FIGURE 39-1
The General tab of Management Studio’s Server Properties dialog
Result:
ProductVersion ProductLevel Edition
10.0.1600.22 RTM Enterprise Edition
In the preceding result, theProductVersionindicates the SQL Server product version number The
ProductLevelindicates the SQL Server product level At the time of writing this chapter, we did not
have any service packs for SQL Server 2008 and the product level isRTM(Release to Manufacturing)
If a SQL Server service pack is installed, the product level will indicate the service pack level too
For example, if you run the preceding command against your SQL Server 2005 SP3 instance, the
ProductLevelwill return SP3 TheEditionindicates the SQL Server edition
Many of the configuration properties do not take effect until SQL Server is restarted, so the
General tab in the SQL Server Properties (Configure) dialog box displays the current
run-ning values.
Within code, many of the server properties are set by means of thesp_configuresystem stored
pro-cedure When executed without any parameters, this procedure reports the current settings, as in the
following code (word-wrap adjusted to fit on the page):
EXEC sp_configure;
Trang 5Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 886
Part VI Enterprise Data Management
Result:
run_value - - -
max text repl size (B) −1 2147483647 65536 65536
You can always discover the minimum and maximum values for a particular configuration option by running the sp _ configure command with the option, but without any value For example, run
EXEC sp_configure ‘remote login timeout’;
and you’ll discover that the remote login timeout configuration option can have any value in the
range of 0 to 2,147,483,647.
The extended stored procedurexp_msverreports additional server and environment properties:
EXEC xp_msver;
Result:
((SQL_PreRelease).080709-1414 )
Trang 6rights reserved.
a registered trademark of Microsoft Corporation
The information returned by sp_configure is settable, but the information returned by
xp_msver is not.
Configuring the database
The database-level options configure the current database’s behavior regarding ANSI compatibility and
recovery
Most database options can be set in Management Studio within the Database Properties page, which
you can access by right-clicking a database in the console tree and choosing Properties from the context
menu The Options tab is shown in Figure 39-2
The database configuration options can be set using T-SQLALTER DATABASE SEToptions The
follow-ing example sets theAdventureWorks2008database to single-user mode to obtain exclusive access:
ALTER DATABASE AdventureWorks2008 SET SINGLE_USER;
View database configuration options using thesys.databasescatalog view or the
DATABASEPROPERTYEX()function The following example returns all the database properties of
theAdventureWorks2008database:
SELECT * FROM sys.databases WHERE name = ‘AdventureWorks2008’;
Do not use the sp_dboption system stored procedure, as it will be removed in the next
version of SQL Server.
Configuring the connection
Many of the connection-level options configure ANSI compatibility or specific connection-performance
options
Connection-level options are very limited in scope If the option is set within an interactive session, then
the setting is in force until it’s changed or the session ends If the option is set within a stored
proce-dure, then the setting persists only for the life of that stored procedure
Trang 7Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 888
Part VI Enterprise Data Management
FIGURE 39-2
Management Studio’s Database Properties Options tab can be used to configure the most common
database properties
The connection-level options are typically configured by means of theSETcommand The following
code configures how SQL Server handlesnullswithin this current session:
SET ANSI_NULLS OFF;
Result:
Command(s) completed successfully
Connection properties can also be checked by means of theSessionProperty()function:
Select SESSIONPROPERTY (’ANSI_NULLS’);
Result:
0
Trang 8Management Studio allows you to set several query properties You can review and set these properties
for current queries by clicking the Query menu and then Query Options For all future connections,
review and set the properties by clicking the Tools menu and then Options Figure 39-3 shows an
example of the ANSI settings that SQL Server will use to run the queries
To view current settings of connection-level options, query the sys.dm_exec_connections
dynamic management view.
FIGURE 39-3
The ANSI settings that SQL Server uses to run your queries
Configuration Options
Because so many similar configuration options are controlled by different commands and at different
lev-els (server, database, connection), this section organizes the configuration options by topic, rather than
command or level
Displaying the advanced options
As with many operations, displaying advanced options can be achieved using several methods One
method is to query thesys.configurationscatalog view as shown here:
SELECT name, minimum, maximum, value, value_in_use
FROM sys.configurations
WHERE is_advanced = 1
ORDER BY name;
Trang 9Nielsen c39.tex V4 - 07/21/2009 2:17pm Page 890
Part VI Enterprise Data Management
The preceding example will display all the SQL Server advanced options To display all the options,
comment theWHEREclause Another method to display the advanced options is to turn on theshow
advanced optionsconfiguration, as follows:
EXEC sp_configure ‘show advanced options’, 1;
RECONFIGURE;
After a configuration setting is changed with sp_configure , the RECONFIGURE command causes the changes to take effect If you don’t run RECONFIGURE , then the config_value
field will still show the change, but the change won’t appear in the run_value field, even if you restart
the service Some configuration changes take effect only after SQL Server is restarted.
After you enable the advanced option display, you can use thesp_configurecommand to display a
list of all of the options:
EXEC sp_configure;
Result (with advanced options enabled):
run_value - - - -
default full-text language 0 2147483647 1033 1033
Trang 10filestream access level 0 2 2 2
max server memory (MB) 16 2147483647 2147483647
2147483647
65536
min memory per query (KB) 512 2147483647 1024
1024
4096
600