<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://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 : compatibility level</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/tags/compatibility+level/default.aspx</link><description>Tags: compatibility level</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://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://sqlblog.com/blogs/kalen_delaney/comments/7392.aspx</comments><wfw:commentRss>http://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://sqlblog.com/aggbug.aspx?PostID=7392" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/kalen_delaney/archive/tags/compatibility+level/default.aspx">compatibility level</category><category domain="http://sqlblog.com/blogs/kalen_delaney/archive/tags/indexes/default.aspx">indexes</category><category domain="http://sqlblog.com/blogs/kalen_delaney/archive/tags/SET+Options/default.aspx">SET Options</category></item></channel></rss>