<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>SQL Server Blogs</title><link>http://sqlblogcasts.com/blogs/</link><description>Voices from the UK SQL Server Community</description><dc:language>en-US</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/UkSqlServerCommunityBlogs" /><feedburner:info uri="uksqlservercommunityblogs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>PAL and SQLDiag with SQL Server 2012</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/YKXScsXb8ho/PAL-and-DQLDiag-with-SQL-Server-2012.aspx</link><pubDate>Thu, 24 May 2012 22:56:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16221</guid><dc:creator>MartinBell</dc:creator><slash:comments>0</slash:comments><description>After a new release you may expect a delay in updating codeplex projects to the latest SQL Server version. Here are some tips on using PAL and SDCT until a version that officially supports SQL Server 2012 is available....(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/24/PAL-and-DQLDiag-with-SQL-Server-2012.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16221" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/PAL/default.aspx">PAL</category><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/SQL+Server+2012/default.aspx">SQL Server 2012</category><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/SQLDiag/default.aspx">SQLDiag</category><feedburner:origLink>http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/24/PAL-and-DQLDiag-with-SQL-Server-2012.aspx</feedburner:origLink></item><item><title>How atomic is a SELECT INTO?</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/j4SysXm0iYY/how-atomic-is-a-select-into.aspx</link><pubDate>Tue, 22 May 2012 22:47:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16215</guid><dc:creator>leo.pasta</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Last week I got an interesting situation that prompted me to challenge a long standing assumption. I always thought that a &lt;em&gt;SELECT INTO&lt;/em&gt; was an atomic statement, i.e. it would either complete successfully or the table would not be created.&lt;/p&gt;

&lt;p&gt;So I got very surprised when, after a “select into” query was chosen as a deadlock victim, the next execution (as the app would handle the deadlock and retry) would fail with:&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000" face="Courier New"&gt;Msg 2714, Level 16, State 6, Line 1 
    &lt;br /&gt;There is already an object named &amp;#39;#test&amp;#39; in the database.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;The only hypothesis we could come up was that the “create table” part of the statement was committed independently from the actual “insert”. We can confirm that by capturing the “Transaction Log” event on Profiler (filtering by SPID0). The result is that when we run:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;INTO&lt;/span&gt; #results &lt;span class="kwrd"&gt;FROM&lt;/span&gt; master.sys.objects&lt;/pre&gt;

&lt;p&gt;we get the following output on Profiler:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/leopasta/image_188315F8.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/leopasta/image_thumb_2C2FFF8C.png" width="689" height="99" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It is easy to see the two independent transactions. Although this behaviour was a surprise to me, it is very easy to workaround it if you feel the need (as we did in this case). You can either change it into independent “CREATE TABLE / INSERT SELECT” or you can enclose the SELECT INTO in an explicit transaction:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; XACT_ABORT &lt;span class="kwrd"&gt;ON&lt;/span&gt;
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;TRANSACTION&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;INTO&lt;/span&gt; #results &lt;span class="kwrd"&gt;FROM&lt;/span&gt; master.sys.objects
COMMIT&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/leopasta/image_3CC7FA7A.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/leopasta/image_thumb_4D5FF568.png" width="679" height="142" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16215" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/SELECT+INTO/default.aspx">SELECT INTO</category><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Temp+Tables/default.aspx">Temp Tables</category><feedburner:origLink>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/how-atomic-is-a-select-into.aspx</feedburner:origLink></item><item><title>Coming back from (blog) retirement</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/-1PFfTIU0n8/coming-back-from-blog-retirement.aspx</link><pubDate>Tue, 22 May 2012 21:30:54 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16214</guid><dc:creator>leo.pasta</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;So, it has been more than 3 years without a single blog post. I wished I could have a decent excuse for it, but in the end, I guess it boils down to laziness and procrastination. :-)&lt;/p&gt;  &lt;p&gt;Even though I learned a lot in that period (and added a feel tricks to my bag), I couldn’t find the will to sit down and write. I hope all my readers (yes mom and dad, I’m talking to you) have not been disappointed.&lt;/p&gt;  &lt;p&gt;I will try really hard not to let routine take over. I don’t expect I will be the most active blogger in the community, but hopefully a couple of posts per month is a good target to aim.&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16214" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/leopasta/archive/tags/Personal/default.aspx">Personal</category><feedburner:origLink>http://sqlblogcasts.com/blogs/leopasta/archive/2012/05/22/coming-back-from-blog-retirement.aspx</feedburner:origLink></item><item><title>Changing Server Side Trace Scripts</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/C2JTTpJjRsA/Changing-Server-Side-Trace-Scripts.aspx</link><pubDate>Sun, 20 May 2012 18:38:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16213</guid><dc:creator>MartinBell</dc:creator><slash:comments>0</slash:comments><description>All though Server Side Traces are being depricated they will still be around for some time. This nuggets of code may help make them easier to use....(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/20/Changing-Server-Side-Trace-Scripts.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16213" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/Trace+Files/default.aspx">Trace Files</category><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/Performance+Troubleshooting/default.aspx">Performance Troubleshooting</category><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/SQL+Trace/default.aspx">SQL Trace</category><feedburner:origLink>http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/20/Changing-Server-Side-Trace-Scripts.aspx</feedburner:origLink></item><item><title>SQL Server data platform upgrade - Why upgrade and how best you can reduce pre &amp; post upgrade problems?</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/PF7lGAD__0o/sql-server-data-platform-upgrade-why-upgrade-and-how-best-you-can-reduce-pre-amp-post-upgrade-problems.aspx</link><pubDate>Sat, 19 May 2012 10:26:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16212</guid><dc:creator>ssqa.net</dc:creator><slash:comments>0</slash:comments><description>SQL Server upgrade, let it be database(s) or instance(s) or both the process and procedures must follow best practices in order to reduce any problems that may occur even after the platform is upgraded. The success of any project relies upon the simpler methods of implementation and a process to reduce the complexity in testing to ensure a successful outcome. Also the topic has been a popular topic that .... read more from here ......(&lt;a href="http://sqlblogcasts.com/blogs/ssqanet/archive/2012/05/19/sql-server-data-platform-upgrade-why-upgrade-and-how-best-you-can-reduce-pre-amp-post-upgrade-problems.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16212" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/best+practices/default.aspx">best practices</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/benefits/default.aspx">benefits</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/plan+guide/default.aspx">plan guide</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/upgrade/default.aspx">upgrade</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/upgrade+advisor/default.aspx">upgrade advisor</category><feedburner:origLink>http://sqlblogcasts.com/blogs/ssqanet/archive/2012/05/19/sql-server-data-platform-upgrade-why-upgrade-and-how-best-you-can-reduce-pre-amp-post-upgrade-problems.aspx</feedburner:origLink></item><item><title>Microsoft SQL Server 2008 R2 Administration Cookbook</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/wfkRQzANq00/microsoft-sql-server-2008-r2-administration-cookbook.aspx</link><pubDate>Fri, 18 May 2012 22:25:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16211</guid><dc:creator>ssqa.net</dc:creator><slash:comments>0</slash:comments><description>Its one year on my first book released, keeping aside the financial gains from this book I&amp;#39;m more happy to achieve one of the important goals from my career. This is something big in my life to announce, it gives immensive pleasure and happiness to share about my first book (hard paper) and eBook release, titled : Microsoft SQL Server 2008 R2 Administration Cookbook is released and out now. share my experience and task based real-world best practices in a cookbook style. My thanks to the technical...(&lt;a href="http://sqlblogcasts.com/blogs/ssqanet/archive/2012/05/18/microsoft-sql-server-2008-r2-administration-cookbook.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16211" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/best+practices/default.aspx">best practices</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/dba/default.aspx">dba</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/developer/default.aspx">developer</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/architects/default.aspx">architects</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/cookbook/default.aspx">cookbook</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/sql+server+2008r2/default.aspx">sql server 2008r2</category><category domain="http://sqlblogcasts.com/blogs/ssqanet/archive/tags/administration/default.aspx">administration</category><feedburner:origLink>http://sqlblogcasts.com/blogs/ssqanet/archive/2012/05/18/microsoft-sql-server-2008-r2-administration-cookbook.aspx</feedburner:origLink></item><item><title>SQL Server 2012 - Upgrade Whitepaper</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/X69vdHCWOHc/sql-server-2012-upgrade-whitepaper.aspx</link><pubDate>Thu, 17 May 2012 16:24:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16210</guid><dc:creator>JustinL</dc:creator><slash:comments>0</slash:comments><description>Just a short note to mention Microsoft have released the Technical Reference Guide for upgrading to SQL Server 2012.

&lt;br /&gt;&lt;br /&gt;
The paper is available for download here: &lt;a href="http://tinyurl.com/84xm5b4"&gt;http://tinyurl.com/84xm5b4&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;

There&amp;#39;s some interesting details on approaches to upgrade, including features such as high availability, full-text search, service broker and other components (SSIS, SSAS, SSRS).  Additionally, there&amp;#39;s a (fairly) recent initiative to organise and present TechNet content more easily, there&amp;#39;s some useful content (with interesting presentation) at the link below:
&lt;br /&gt;&lt;br /&gt;

&lt;a href="http://technet.microsoft.com/en-us/library/hh393545.aspx"&gt;http://technet.microsoft.com/en-us/library/hh393545.aspx&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;

Good luck planning your upgrades,
&lt;br /&gt;&lt;br /&gt;

Regards,
&lt;br /&gt;&lt;br /&gt;


Justin&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16210" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/justinl/archive/tags/upgrade/default.aspx">upgrade</category><category domain="http://sqlblogcasts.com/blogs/justinl/archive/tags/reference+guide/default.aspx">reference guide</category><category domain="http://sqlblogcasts.com/blogs/justinl/archive/tags/sql+server+2012/default.aspx">sql server 2012</category><feedburner:origLink>http://sqlblogcasts.com/blogs/justinl/archive/2012/05/17/sql-server-2012-upgrade-whitepaper.aspx</feedburner:origLink></item><item><title>Read Committed Snapshot Isolation– Two Considerations</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/5wAQllmVpCQ/read-committed-snapshot-isolation-two-considerations.aspx</link><pubDate>Fri, 11 May 2012 20:27:20 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16206</guid><dc:creator>GavinPayneUK</dc:creator><slash:comments>0</slash:comments><description>&amp;#160; The Read Committed Snapshot database option in SQL Server, known perhaps more accurately as Read Committed Snapshot Isolation or RCSI, can be enabled to help readers from blocking writers and writers from blocking readers.&amp;#160; However, enabling it can cause two issues with the tempdb database which are often overlooked. One can slow down queries, the other can cause queries to fail . Overview of RCSI Enabling the option changes the behaviour of the default SQL Server isolation level, read...(&lt;a href="http://sqlblogcasts.com/blogs/gavinpayneuk/archive/2012/05/11/read-committed-snapshot-isolation-two-considerations.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16206" width="1" height="1"&gt;</description><feedburner:origLink>http://sqlblogcasts.com/blogs/gavinpayneuk/archive/2012/05/11/read-committed-snapshot-isolation-two-considerations.aspx</feedburner:origLink></item><item><title>“Query cost (relative to the batch)” &lt;&gt; Query cost relative to batch</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/ljrdZPgri1c/query-cost-relative-to-the-batch-lt-gt-query-cost-relative-to-batch.aspx</link><pubDate>Thu, 10 May 2012 10:19:17 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16203</guid><dc:creator>Dave Ballantyne</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;OK, so that is quite a contradictory title, but unfortunately it is true that a common misconception is that the query with the highest percentage relative to batch is the worst performing.&amp;#160; Simply put, it is a lie, or more accurately we dont understand what these figures mean.&lt;/p&gt;  &lt;p&gt;Consider the two below simple queries:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Person.BusinessEntity
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; Person.BusinessEntityAddress
&lt;span class="kwrd"&gt;ON&lt;/span&gt; Person.BusinessEntity.BusinessEntityID = Person.BusinessEntityAddress.BusinessEntityID
&lt;span class="kwrd"&gt;go&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Sales.SalesOrderDetail
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; Sales.SalesOrderHeader
&lt;span class="kwrd"&gt;ON&lt;/span&gt; Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderID&lt;/pre&gt;

&lt;p&gt;After executing these and looking at the plans, I see this :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/image_725069FC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/sqlandthelike/image_thumb_38CD5A05.png" width="663" height="182" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, a 13% / 87% split ,&amp;#160; but 13% / 87% of WHAT ? CPU ? Duration ? Reads ? Writes ? or some magical weighted algorithm ?&amp;#160; &lt;/p&gt;

&lt;p&gt;In a Profiler trace of the two we can find the metrics we are interested in.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/image_1126DDDB.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/sqlandthelike/image_thumb_65E246D3.png" width="660" height="48" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CPU and duration are well out but what about reads (210 and 1935)? To save you doing the maths, though you are more than welcome to, that’s a 90.2% / 9.8% split.&amp;#160; Close, but no cigar.&lt;/p&gt;

&lt;p&gt;Lets try a different tact.&amp;#160; Looking at the execution plan the “Estimated Subtree cost” of query 1 is 0.29449 and query 2 its 1.96596.&amp;#160; Again to save you the maths that works out to 13.03% and 86.97%, round those and thats the figures we are after.&amp;#160; But, what is the worrying word there ? “Estimated”.&amp;#160; &lt;/p&gt;

&lt;p&gt;So these are not “actual”&amp;#160; execution costs,&amp;#160; but what’s the problem in comparing the estimated costs to derive a meaning of “Most Costly”.&amp;#160; Well, in the case of simple queries such as the above , probably not a lot.&amp;#160; In more complicated queries , a fair bit.&lt;/p&gt;

&lt;p&gt;By modifying the second query to also show the total number of lines on each order&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; *,&lt;span class="kwrd"&gt;COUNT&lt;/span&gt;(*) &lt;span class="kwrd"&gt;OVER&lt;/span&gt; (PARTITION &lt;span class="kwrd"&gt;BY&lt;/span&gt; Sales.SalesOrderDetail.SalesOrderID)
 &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Sales.SalesOrderDetail
&lt;span class="kwrd"&gt;JOIN&lt;/span&gt; Sales.SalesOrderHeader
&lt;span class="kwrd"&gt;ON&lt;/span&gt; Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderID&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;The split in percentages is now 6% / 94% and the profiler metrics are :&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/image_10BAAAE6.png"&gt;&lt;font face="Tahoma"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/sqlandthelike/image_thumb_1E8CF0E1.png" width="657" height="47" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/pre&gt;

&lt;p&gt;Even more of a discrepancy. &lt;/p&gt;

&lt;p&gt;Estimates can be out with actuals for a whole host of reasons,&amp;#160; scalar UDF’s are a particular bug bear of mine and in-fact the cost of a udf call is entirely hidden inside the execution plan.&amp;#160; It always estimates to 0 (well, a very small number).&lt;/p&gt;

&lt;p&gt;Take for instance the following udf&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Create&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; dbo.udfSumSalesForCustomer(@CustomerId &lt;span class="kwrd"&gt;integer&lt;/span&gt;)
&lt;span class="kwrd"&gt;returns&lt;/span&gt; money
&lt;span class="kwrd"&gt;as&lt;/span&gt;
&lt;span class="kwrd"&gt;begin&lt;/span&gt;
   &lt;span class="kwrd"&gt;Declare&lt;/span&gt; @&lt;span class="kwrd"&gt;Sum&lt;/span&gt; money
   &lt;span class="kwrd"&gt;Select&lt;/span&gt; @&lt;span class="kwrd"&gt;Sum&lt;/span&gt;= &lt;span class="kwrd"&gt;SUM&lt;/span&gt;(SalesOrderHeader.TotalDue)
     &lt;span class="kwrd"&gt;from&lt;/span&gt; Sales.SalesOrderHeader
    &lt;span class="kwrd"&gt;where&lt;/span&gt; CustomerID = @CustomerId
   &lt;span class="kwrd"&gt;return&lt;/span&gt; @&lt;span class="kwrd"&gt;Sum&lt;/span&gt;
end&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;If we have two statements , one that fires the udf and another that doesn&amp;#39;t:&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Select&lt;/span&gt; CustomerID
  &lt;span class="kwrd"&gt;from&lt;/span&gt; Sales.Customer
 &lt;span class="kwrd"&gt;order&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; CustomerID
&lt;span class="kwrd"&gt;go&lt;/span&gt;
&lt;span class="kwrd"&gt;Select&lt;/span&gt; CustomerID,dbo.udfSumSalesForCustomer(Customer.CustomerID)
  &lt;span class="kwrd"&gt;from&lt;/span&gt; Sales.Customer
 &lt;span class="kwrd"&gt;order&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; CustomerID&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;The costs relative to batch is a 50/50 split, but the has to be an actual cost of firing the udf.  Indeed profiler shows us :&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/image_294A4836.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/sqlandthelike/image_thumb_092F3B79.png" width="664" height="54" /&gt;&lt;/a&gt;&lt;/pre&gt;

&lt;p&gt;&lt;font face="Tahoma"&gt;No where even remotely near 50/50!!!!&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Tahoma"&gt;Moving forward to window framing functionality in SQL Server 2012 the optimizer sees ROWS and RANGE ( see &lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/archive/2011/09/22/rows-or-range-what-s-the-difference.aspx"&gt;here&lt;/a&gt; for their functional differences) as the same ‘cost’ too&lt;/font&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; SalesOrderDetailID,SalesOrderId,
       &lt;span class="kwrd"&gt;SUM&lt;/span&gt;(LineTotal) &lt;span class="kwrd"&gt;OVER&lt;/span&gt;(PARTITION &lt;span class="kwrd"&gt;BY&lt;/span&gt; salesorderid 
         &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; Salesorderdetailid RANGE unbounded preceding)
&lt;span class="kwrd"&gt;from&lt;/span&gt; Sales.SalesOrderdetail
&lt;span class="kwrd"&gt;go&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; SalesOrderDetailID,SalesOrderId,
       &lt;span class="kwrd"&gt;SUM&lt;/span&gt;(LineTotal) &lt;span class="kwrd"&gt;OVER&lt;/span&gt;(PARTITION &lt;span class="kwrd"&gt;BY&lt;/span&gt; salesorderid 
       &lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; Salesorderdetailid &lt;span class="kwrd"&gt;Rows&lt;/span&gt; unbounded preceding)
&lt;span class="kwrd"&gt;from&lt;/span&gt; Sales.SalesOrderdetail&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;By now it wont be a great display to show you the Profiler trace reads a *tiny* bit different.&lt;/font&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;a href="http://sqlblogcasts.com/blogs/sqlandthelike/image_649DADF4.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblogcasts.com/blogs/sqlandthelike/image_thumb_767A41C1.png" width="687" height="55" /&gt;&lt;/a&gt;&lt;/pre&gt;

&lt;p&gt;So moral of the story, Percentage relative to batch can give a rough ‘finger in the air’ measurement, but dont rely on it as fact.&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16203" width="1" height="1"&gt;</description><feedburner:origLink>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2012/05/10/query-cost-relative-to-the-batch-lt-gt-query-cost-relative-to-batch.aspx</feedburner:origLink></item><item><title>Changing SQL Server Port with Powershell</title><link>http://feedproxy.google.com/~r/UkSqlServerCommunityBlogs/~3/LkZxgXjkOg0/Changing-SQL-Server-Port-with-Powershell.aspx</link><pubDate>Mon, 07 May 2012 16:48:00 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16198</guid><dc:creator>MartinBell</dc:creator><slash:comments>1</slash:comments><description>Powershell will be even more important when managing SQL Server on Windows Server Core so it&amp;#39;s time to build up your toolbox of scripts....(&lt;a href="http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/07/Changing-SQL-Server-Port-with-Powershell.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16198" width="1" height="1"&gt;</description><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/POWERSHELL/default.aspx">POWERSHELL</category><category domain="http://sqlblogcasts.com/blogs/martinbell/archive/tags/WMI/default.aspx">WMI</category><feedburner:origLink>http://sqlblogcasts.com/blogs/martinbell/archive/2012/05/07/Changing-SQL-Server-Port-with-Powershell.aspx</feedburner:origLink></item></channel></rss>

