<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Kalen Delaney : SET Options</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/SET+Options/default.aspx</link><description>Tags: SET Options</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Did You Know? Things Keep Changing</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/06/19/things-keep-changing.aspx</link><pubDate>Thu, 19 Jun 2008 19:07:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:7392</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>0</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/7392.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=7392</wfw:commentRss><description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sqlmag.com/Article/ArticleID/99513/sql_server_99513.html" target=_blank&gt;My Thursday commentary for the SQL Server Magazine Update e-newsletter&lt;/A&gt; discussed quiet changes in SQL Server 2005 and I just realized there's another one I wanted to mention. &lt;/P&gt;
&lt;P&gt;If you use Indexed Views at all, you're probably aware that there is a set of SET options that must on set appropriately in order for your indexed views to work as planned. One of the requirements is that ARITHABORT must be ON. In SQL Server 2000, this value had to be set explicitly. (But frequently it was set by your connection, so you didn't have to worry about it.)&amp;nbsp; &lt;/P&gt;
&lt;P&gt;In SQL 2005, if you (or your connection) enabled the setting ANSI_WARNINGS, ARITHABORT is automatically enabled. &lt;/P&gt;
&lt;P&gt;I dug around and found the reference to this change in the BOL at &lt;BR&gt;&lt;A title=http://msdn.microsoft.com/en-us/library/ms190306.aspx href="http://msdn.microsoft.com/en-us/library/ms190306.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms190306.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;What the article doesn't make completely clear is that even if you explicitly set ARITHABORT to OFF, as long as ANSI_WARNINGS is ON, SQL Server will behave as if ARITHABORT is ON.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The SET options are particularly important when updating a table on which an indexed view is built. If the SET options have the incorrect settings, the update will actually fail.&lt;/P&gt;
&lt;P&gt;Let's look at an example on SQL Server 2005, using the old pubs database. &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- First, create the view and the index&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;USE pubs&lt;BR&gt;GO&lt;BR&gt;CREATE VIEW sum_sales WITH SCHEMABINDING&lt;BR&gt;AS&lt;BR&gt;SELECT type, sum(isnull(ytd_sales,0)) AS total_sales, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count_big(*) AS number_sales&lt;BR&gt;FROM dbo.titles&lt;BR&gt;GROUP BY type; &lt;BR&gt;GO&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;CREATE UNIQUE CLUSTERED INDEX idxv_sales_by_type &lt;BR&gt;&amp;nbsp;&amp;nbsp; ON sum_sales(type);&lt;BR&gt;GO&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- Next, verify the settings&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;SELECT ansi_warnings, arithabort &lt;BR&gt;FROM sys.dm_exec_sessions&lt;BR&gt;WHERE session_id = @@SPID;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- You should see that both options are ON (1).&amp;nbsp; &lt;BR&gt;-- Update the titles table, and it should succeed.&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;UPDATE dbo.titles&lt;BR&gt;SET ytd_sales = ytd_sales + 1&lt;BR&gt;WHERE title_id = 'BU1032';&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;--Now change ARITHABORT TO OFF, verify the settings, and update:&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;SET ARITHABORT OFF;&lt;BR&gt;GO&lt;BR&gt;SELECT ansi_warnings, arithabort &lt;BR&gt;FROM sys.dm_exec_sessions&lt;BR&gt;WHERE session_id = @@SPID;&lt;BR&gt;GO&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;UPDATE dbo.titles&lt;BR&gt;SET ytd_sales = ytd_sales - 1&lt;BR&gt;WHERE title_id = 'BU1032';&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- The above should succeed. &lt;BR&gt;-- Now change ANSI_WARNINGS to OFF:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;SET ANSI_WARNINGS OFF;&lt;BR&gt;GO&lt;BR&gt;SELECT ansi_warnings, arithabort &lt;BR&gt;FROM sys.dm_exec_sessions&lt;BR&gt;WHERE session_id = @@SPID;&lt;BR&gt;GO&lt;BR&gt;UPDATE dbo.titles&lt;BR&gt;SET ytd_sales = ytd_sales - 1&lt;BR&gt;WHERE title_id = 'BU1032';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- The above should fail. &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;-- If we change to SQL 2000 compatibility level, &lt;BR&gt;-- just setting ARITHABORT OFF will cause the update to fail:&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;EXEC sp_dbcmptlevel pubs, 80;&lt;BR&gt;GO&lt;BR&gt;SET ANSI_WARNINGS ON;&lt;BR&gt;GO&lt;BR&gt;SET ARITHABORT OFF;&lt;BR&gt;GO&lt;BR&gt;SELECT ansi_warnings, arithabort &lt;BR&gt;FROM sys.dm_exec_sessions&lt;BR&gt;WHERE session_id = @@SPID;&lt;BR&gt;GO&lt;BR&gt;UPDATE dbo.titles&lt;BR&gt;SET ytd_sales = ytd_sales + 1&lt;BR&gt;WHERE title_id = 'BU1032';&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm sure there are lots more quiet changes. They're just so quiet I haven't found them yet! 
&lt;P&gt;Have fun 
&lt;P&gt;&lt;FONT color=#ff00ff size=4&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=7392" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/SET+Options/default.aspx">SET Options</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/indexes/default.aspx">indexes</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/compatibility+level/default.aspx">compatibility level</category></item><item><title>Did You Know?  Nobody upgraded the SET OPTIONS screen in SQL Server Management Studio</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2007/07/17/did-you-know-nobody-upgraded-the-set-options-screen-in-sql-server-management-studio.aspx</link><pubDate>Tue, 17 Jul 2007 22:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:1788</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>3</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/1788.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=1788</wfw:commentRss><description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SQL Server Management Studio, the screen where you choose which SET options to enable for all connections appears to be left over from SQL Server 2000. I know there are a lot of different dialog boxes available through the Tools | Options menu, but I find it amazing that this one was completely overlooked when updating the old Enterprise Manager GUI. &lt;/P&gt;
&lt;P&gt;Here's how to get to the dialog: 
&lt;P&gt;Tools | Options 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Then expand Query Execution to SQL Server and then to Advanced...&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The list of the set options to enable does not include anything new in SQL Server 2005. 
&lt;P&gt;1. It does not include SET SHOWPLAN_XML or SET STATISTICS XML (but includes SHOWPLAN_TEXT) 
&lt;P&gt;2. Transaction Isolation Level does not include SNAPSHOT 
&lt;P&gt;3. Deadlock Priority only allows NORMAL and LOW, not the numbers -10 to 10, or the value HIGH &lt;BR&gt;&amp;nbsp;&amp;nbsp; (see my earlier post: &lt;A title=http://sqlblog.com/blogs/kalen_delaney/archive/2006/09/09/192.aspx href="http://sqlblog.com/blogs/kalen_delaney/archive/2006/09/09/192.aspx"&gt;http://sqlblog.com/blogs/kalen_delaney/archive/2006/09/09/192.aspx&lt;/A&gt;&amp;nbsp;) 
&lt;P&gt;Maybe there are others that I haven't noticed yet. 
&lt;P&gt;So now you know... 
&lt;P&gt;~Kalen&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=1788" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Upgrade/default.aspx">Upgrade</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/SET+Options/default.aspx">SET Options</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Management+Tools/default.aspx">Management Tools</category></item></channel></rss>