<?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>Search results matching tag 'Testing'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Testing&amp;orTags=0</link><description>Search results matching tag 'Testing'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Geek City: What Triggered This Post?</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2012/12/31/what-triggered-this-post.aspx</link><pubDate>Tue, 01 Jan 2013 00:00:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46911</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;p&gt;I’d really like to get another post up onto my much neglected blog before the end of 2012. This will also start one of my New Year’s resolutions, which is to write at least one blog post a month. I’m going to tell you about a change in SQL Server that wasn’t announced in any “What’s New” list that I ever saw, perhaps because it was just a chance in internal behavior, and nothing that required any change in user applications. &lt;/p&gt;  &lt;p&gt;Do you retest what you know is true for every new version? When I update my books, I do test all the scripts, but if there isn’t a script, I don’t retest every ‘fact’ that I have known for years is true. And sometimes, things change. And sometimes my reviewers notice those unreported changes, and sometimes they don’t. &lt;/p&gt;  &lt;p&gt;You might be aware of the fact that SQL Server can perform UPDATE operations in two different ways. The UPDATE can be performed as a two-step process: delete the old row and then insert a whole new row, or, the UPDATE can be performed (much more efficiently) as an update-in-place.&amp;nbsp; When the two-step UPDATE is performed, it is a LOT more work. Not only does SQL Server have to log the entire old row and the entire new row, but each nonclustered index is also modified twice, and each of those index changes also has to be logged. So it’s nice when an update-in-place is done, because only the bytes changed are logged, and only indexes on the updated columns are affected. &lt;/p&gt;  &lt;p&gt;Prior to SQL Server 7, there were actually four different ways that UPDATE could be done. The two-step UPDATE had some variations that could make it even slower in some cases! But that was a long time ago, so I’m not going to go into the details now. But I will say that back then, in order to get an update-in-place to occur, there was a big long list of prerequisites that had to be met and if you missed just one, you’d get one of the slower UPDATE operations. &lt;/p&gt;  &lt;p&gt;As of SQL Server 7, update-in-place became the default. The only time it doesn’t happen is when the row can’t stay in the same location (such as when you update a clustered index key column) or when SQL Server really needs the old and new versions of the row. &lt;/p&gt;  &lt;p&gt;In SQL 7, one of the places that SQL needed the old and new version of the updates rows was when processing triggers. Triggers need the transaction log to get the contents for the DELETED and INSERTED pseudo-tables. And because triggers needed the entire old and new versions of the updated rows, the UPDATE was performed as a two-step operation. DELETE the old row, log the entire old row, and the INSERT the new row with the new values, and log the entire new row. &lt;/p&gt;  &lt;p&gt;But as of 2005, we now have the version store, primarily used for SNAPSHOT isolation, but available for other uses as well. In SNAPSHOT isolation, the version stores stores ‘old versions’ of rows that have been updated or deleted.&amp;nbsp; I knew that the version store was also used for triggers, but it only occurred to me just recently that maybe, because the old and new versions of the row were not needed from the log, perhaps UPDATEs did not always need to be performed internally as a two-step UPDATE. &lt;/p&gt;  &lt;p&gt;So I decided to test it out.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;-- DEMO: If there is an UPDATE trigger, are updates logged as DELETE + INSERT?        &lt;br&gt;-- First build a new database.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;USE master;        &lt;br&gt;GO         &lt;br&gt;IF (SELECT db_id('TestTrigger')) IS NOT NULL         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DROP DATABASE TestTrigger;         &lt;br&gt;GO         &lt;br&gt;CREATE DATABASE TestTrigger;         &lt;br&gt;GO         &lt;br&gt;ALTER DATABASE TestTrigger SET RECOVERY SIMPLE;         &lt;br&gt;GO         &lt;br&gt;SELECT db_id('TestTrigger');         &lt;br&gt;GO &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;USE TestTrigger;        &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;-- Just for a warmup, look at the function fn_dblog, which works in the current database&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;SELECT * FROM fn_dblog(null, null);        &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Create a new table to work with        &lt;br&gt;IF (SELECT object_id('objects')) IS NOT NULL         &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DROP TABLE objects;         &lt;br&gt;GO         &lt;br&gt;SELECT TOP 100 * INTO objects FROM sys.objects;         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Create a clustered index on the table        &lt;br&gt;CREATE CLUSTERED INDEX objects_clustered on objects(name);         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- First examine an update we know is NOT done in place,        &lt;br&gt;-- i.e. updating a clustered key value&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;UPDATE objects SET name = 'newrowsets' WHERE name = 'sysrowsets';        &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Look at last 10 rows; notice a LOP_DELETE_ROWS and LOP_INSERT_ROWS        &lt;br&gt;-- The AllocUniteName column shows the object affected is the clustered index on dbo.objects         &lt;br&gt;SELECT Operation, [Transaction ID], AllocUnitName FROM fn_dblog(null, null);         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Consolas"&gt;-- Now examine an update we know is&amp;nbsp; done in place,        &lt;br&gt;-- i.e. updating an unindexed column on a table with no triggers         &lt;br&gt;UPDATE objects SET parent_object_id = 1 WHERE name = 'sysfiles1';         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Look at last 3 rows; notice a LOP_MODIFY_ROW on the dbo.objects allocation unit        &lt;br&gt;SELECT Operation, [Transaction ID], AllocUnitName FROM fn_dblog(null, null);         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Create an update trigger        &lt;br&gt;-- Will the update be done with the siple LOP_MODIFY_ROW or with the LOP_DELETE_ROWS and LOP_INSERT_ROWS         &lt;br&gt;CREATE TRIGGER trg_update_objects ON objects FOR UPDATE         &lt;br&gt;as         &lt;br&gt;SELECT * FROM DELETED; SELECT * FROM INSERTED;         &lt;br&gt;RETURN;         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Now perform update again        &lt;br&gt;UPDATE objects SET parent_object_id = 10 WHERE name = 'sysfiles1';         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font face="Consolas"&gt;-- Look at last 3 rows; notice a LOP_MODIFY_ROW        &lt;br&gt;SELECT * FROM fn_dblog(null, null);         &lt;br&gt;GO&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Since the database is in SIMPLE recovery model, you can issue a CHECKPOINT before each UPDATE if you want to reduce the number of rows in the log to make it easier to examine. &lt;/p&gt;  &lt;p&gt;So it seems that I need to update my course and some of my writings. There might also be special cases that still require that an two-step UPDATE be performed in the presence of triggers, but it seems like a two-step UPDATE is not ALWAYS required anymore. That is very good news!&lt;/p&gt;  &lt;p&gt;I hope you all have a wonder-filled and joyous New Year!&lt;/p&gt;  &lt;p&gt;&lt;font color="#800040" size="4"&gt;~Kalen&lt;/font&gt;&lt;/p&gt;</description></item><item><title>CloudSeeder: CLR Stored Procedures For Creating CPU Pressure</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2012/10/23/cloudseeder-clr-stored-procedures-for-creating-cpu-pressure.aspx</link><pubDate>Tue, 23 Oct 2012 19:49:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:45743</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Sometimes, in the interest of testing various scenarios that your server might encounter, it's useful to be able to quickly simulate some condition or another. I/O, memory, CPU pressure, and so on.&lt;/p&gt;&lt;p&gt;This latter one is something I've been playing with a lot recently.&lt;b&gt; CPU pressure in SQL Server creates all sorts of interesting side-effects&lt;/b&gt;, such as exacerbating waits and making various other conditions much easier to reproduce.&lt;/p&gt;&lt;p&gt;In order to make this simpler, I've created the attached CLR library. This is a simple pair of stored procedures:&lt;/p&gt;&lt;p&gt;&lt;b&gt;startSeeding&lt;/b&gt; takes two arguments:&lt;b&gt; The first parameter is the number of threads you'd like to create&lt;/b&gt;, and &lt;b&gt;the second is a bit, indicating whether or not the threads should be affinitized&lt;/b&gt;. If they are, the threads will run preemptively, and the CPU pressure will be of the external sort. If they are not affinitized, the pressure will be of the internal sort, and you'll be able to see SQL Server scheduler contention. Of course &lt;b&gt;you can run the procedure two or more times and create a mix of threads&lt;/b&gt;, if that's what you'd like to do.&lt;/p&gt;&lt;p&gt;&lt;b&gt;stopSeeding&lt;/b&gt; takes no arguments. It attempts to cancel all of the threads that have been started.&lt;/p&gt;&lt;p&gt;"Installing" the script is easy. Create a database on a server that has CLR enabled. Make the database trustworthy to bypass CLR security restrictions. And then run the script to create the objects. The code was compiled for .NET 3.5, so this should work on either SQL Server 2008, 2008R2, and 2012.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Be careful&lt;/b&gt; about how many threads you create. It's amazing how quickly things can get out of hand. Start small. Trust me on this.&lt;br&gt;&lt;/p&gt;&lt;p&gt;On that note, &lt;b&gt;I make absolutely no guarantees that this won't crash your server, or worse.&lt;/b&gt; As a matter of fact, that's kind of the point!&lt;/p&gt;&lt;p&gt;&lt;b&gt;Enjoy&lt;/b&gt;, and let me know if you have any feedback, feature requests, or whatever.&lt;br&gt;&lt;/p&gt;</description></item><item><title>Performance impact: driving up context switches/sec</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2012/01/12/performance-impact-driving-up-context-switches-sec.aspx</link><pubDate>Thu, 12 Jan 2012 05:23:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40981</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;Too many context switches per second are considered bad for your database performance. But how many is too many has never been clear. With the core count of new servers going up rapidly, it becomes even less clear how we should evaluate this counter to help understand the SQL Server behavior in the environments we support. Recognizing that any attempt to rehash what is already said/recommended out there will more likely be a disservice than a service, I’d like to look at it from a different angle, and hopefully contribute to its understanding with some data points.&lt;/p&gt;  &lt;p&gt;Personally, I subscribe to the belief that one of the best ways to understand a behavior is to be able to create and manipulate the behavior on demand. And it naturally follows to ask: how can we drive up the value of the System\Context Switches/sec counter with a SQL Server workload?&lt;/p&gt;  &lt;p&gt;Knowing how SQL Server schedules its tasks, I’d expect to be able to drive up context switches/sec by running a lot of very small tasks.&lt;/p&gt;  &lt;p&gt;And that is indeed the case. Here is how it goes.&lt;/p&gt;  &lt;p&gt;I first create two stored procedures that basically does nothing on the server side. These are just null transactions. (By the way, the parameters in these proc don’t mean anything. They are there because the client program I use expect them and I’m too lazy to modify the client program. Plus, it adds absolutely no value to modify the client code.)&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" bgcolor="#eeeeee"&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;blockquote style="margin-right:0px;" dir="ltr"&gt;           &lt;p&gt;&lt;font size="2" face="Courier New"&gt;CREATE PROC spStockLevel&amp;#160;&amp;#160;&amp;#160; @w_id&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int,                &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @d_id&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tinyint,                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @threshold&amp;#160;&amp;#160;&amp;#160;&amp;#160; smallint                 &lt;br /&gt;AS                 &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SET NOCOUNT ON                &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SELECT 5                &lt;br /&gt;GO&lt;/font&gt;&lt;/p&gt;            &lt;p&gt;&lt;font size="2" face="Courier New"&gt;CREATE PROC spOrderStatus&amp;#160;&amp;#160; @w_id&amp;#160; int,               &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @d_id&amp;#160; tinyint,&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @c_id&amp;#160;&amp;#160; int,                &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @c_last char(16) = ''                &lt;br /&gt;AS                &lt;br /&gt;&amp;#160;&amp;#160; SET NOCOUNT ON                &lt;br /&gt;&amp;#160;&amp;#160; SELECT 1, 'Jones', '&lt;/font&gt;&lt;font size="2" face="Courier New"&gt;John', 'M', '2012-01-01', 2, 21, 2 &lt;/font&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160; &lt;br /&gt;GO&lt;/font&gt;&lt;/p&gt;         &lt;/blockquote&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;Then, I simulate 200 concurrent users by starting 200 threads on a client and each thread calling these two procs within an infinite loop with no wait between the calls. The following chart shows the sustained values of the Context Switches/sec on a DL580 G7 with four E7-4870 processors when different number of cores are enabled. In all the cases, hyperthreading is enabled. And note that each E7-4870 has 10 cores.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/linchi_shea/Context_switches_09846457.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="Context_switches" border="0" alt="Context_switches" src="http://sqlblog.com/blogs/linchi_shea/Context_switches_thumb_607C560B.png" width="607" height="370" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With this approach, the value of the Context Switches/sec counter is driven into 200,000 to 250,000 per second range. These are pretty high numbers. I have no idea if they can be driven even higher with a different approach. But I know that I have not seen the counter approaching this level in any real production environment. If you have, let us know what kind values you have seen and with what kind of workload.&lt;/p&gt;  &lt;p&gt;I should also report that this null transaction workload fails to push the total processor time very high. See the following chart:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/linchi_shea/CPU_time_privilegded_time_1FDA099C.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="CPU_time_privilegded_time" border="0" alt="CPU_time_privilegded_time" src="http://sqlblog.com/blogs/linchi_shea/CPU_time_privilegded_time_thumb_74293F9F.png" width="623" height="345" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The maximum %Processor Time (_Total) that can be reached by this workload ~24%. And this is not only the case with the different number of core count, but also is the case no matter how many concurrent users (threads) are submitting the transactions. &lt;/p&gt;  &lt;p&gt;It is worth noting, and it is evident from the chart, that the %Privileged Time (_Total) accounts for a very large percentage of the %Processor Time (_Total). In a real production environment, this would spell trouble. With this null transaction workload, I don’t know whether this should be expected and is by design, or something is not behaving properly and the %Privileged Time should be much lower. But I do know that when the transactions are actually doing something useful (e.g. by including some non-trivial SELECT statements), we’ll see the %Privileged Time (_Total) value go down rather quickly. For instance, with the workload used in this previous &lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/06/performance-impact-hyperthreading-for-oltp-queries.aspx"&gt;post&lt;/a&gt;, the %Privileged Time (_Total) is typically around 1% while %Processor Time (_Total) is near 100%. And with that workload (which is doing a lot more useful work in its transactions), the Context Switches/sec counter is typically observed to be less than 49,000.&lt;/p&gt;  &lt;p&gt;How useful are these data points? I’m not really sure. Hey, at least we know that this particular workload can drive up the Context Switches/sec counter. And if this starts a conversation, it would be a plus.&lt;/p&gt;</description></item><item><title>Performance impact: hyperthreading for OLTP queries -- II</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2012/01/11/performance-impact-hyperthreading-for-oltp-queries-ii.aspx</link><pubDate>Wed, 11 Jan 2012 18:51:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40959</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;This is in part a response to a comment by Paul White (&lt;a href="http://twitter.com/SQL_Kiwi"&gt;@SQL_Kiwi&lt;/a&gt;) to my previous post on the &lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/06/performance-impact-hyperthreading-for-oltp-queries.aspx"&gt;performance impact of enabling hyperthreading (HT) on OLTP queries&lt;/a&gt;, and in part due to my desire to capture a more complete set of test data for future investigation on this very topic. I’m posting below the results of re-running the same exact test as described in the previous &lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/06/performance-impact-hyperthreading-for-oltp-queries.aspx"&gt;post&lt;/a&gt; but with the SQL Server instance bumped up to build 10.50.2500 from 10.50.1600. The former is SQL Server 2008 R2 with Service Pack 1, whereas the latter is SQL Server 2008 R2 RTM.&lt;/p&gt;  &lt;p&gt;In addition, I have included the core count as a formal test parameter, and tested the performance impact of enabling HT at the following core counts: 16, 20, 24, 32, and 40. The core count was controlled through the BIOS on machine reboot. The exact BIOS feature for controlling the number of cores is primarily under &lt;strong&gt;System Options&lt;/strong&gt; –&amp;gt; &lt;strong&gt;Processor Options&lt;/strong&gt; –&amp;gt; &lt;strong&gt;Enhanced Processor Core Disable (Intel Core Select)&lt;/strong&gt;. This allows one to enter the number of cores to be enabled per socket.&lt;/p&gt;  &lt;p&gt;The results are as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/linchi_shea/HT_cores_E74870_SQL2008_10.50.2500_11C229C5.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="HT_cores_E7-4870_SQL2008_10.50.2500" border="0" alt="HT_cores_E7-4870_SQL2008_10.50.2500" src="http://sqlblog.com/blogs/linchi_shea/HT_cores_E74870_SQL2008_10.50.2500_thumb_38240D10.png" width="631" height="453" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In the previous post, enabling HT is reported to increase the throughput by 5~7.5%. In the above chart, the increase in the throughput varies between 9% and 14%. So it may appear that SQL Server 2008 R2 SP1 responds slightly better to enabling HT than does SQL Server 2008 R2 RTM. However, because there is always a margin of error in any test, I’d assign more significance to the overall trends and patterns than the exact numbers.&amp;#160; And in both cases, the over trends and patterns are similar in that this particular OLTP workload responded positively to enabling HT on the E7-4870 processors.&lt;/p&gt;</description></item><item><title>Performance impact: hyperthreading for OLTP queries</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2012/01/05/performance-impact-hyperthreading-for-oltp-queries.aspx</link><pubDate>Fri, 06 Jan 2012 04:44:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40853</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P&gt;My &lt;A href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/05/performance-impact-hyperthreading-for-reporting-queries.aspx"&gt;previous post&lt;/A&gt; focuses on the performance impact of enabling hyperthreading (HT) on a machine with four Intel Westmere-EX processors on reporting queries. Let’s turn our attention to OLTP queries.&lt;/P&gt;
&lt;P&gt;To oversimplify it, reporting queries are generally processed by scanning a large number of pages, whereas quick index seeks are the hallmark of OLTP queries.&lt;/P&gt;
&lt;P&gt;The OLTP queries used to check out the hyperthreading impact are the two TPC-C read-only transactions (Order Status and Stock Level), slightly modified to work properly in the test environment. The need to modify these two TPC-C transactions is discussed in an early &lt;A href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/03/evaluating-server-hardware-a-sign-of-the-times.aspx"&gt;post&lt;/A&gt;. Briefly, it’s because in their original forms they don’t scale properly on this 80-cpu test machine running SQL Server 2008 R2. You can find the modified code of these two transactions in the attachment of this post.&lt;/P&gt;
&lt;P&gt;The benchmark described in the &lt;A href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/03/evaluating-server-hardware-a-sign-of-the-times.aspx"&gt;same post&lt;/A&gt; is used to drive the tests whose results are reported here. If you want to find out more about the benchmark, please check out that post, so I won’t duplicate its description here.&lt;/P&gt;
&lt;P&gt;Essentially, with this OLTP benchmark (or workload) I want to see how it behaves when I increase the load level by increasing the number of concurrent users, with and without hyperthreading on a DL580 G7 with four E7-4870 processors (10 cores per processor) and 264GB of RAM. The OS is Windows 2008 R2 Enterprise x64 Edition with SP2 and DBMS is SQL Server 2008 R2 Enterprise x64 Edition (10.50.1600). There is no intra-query parallelism; maxdop is set to 1 in all the cases.&lt;/P&gt;
&lt;P&gt;Four test configurations are examined:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;40 core with HT&lt;/STRONG&gt;&lt;/EM&gt;. That is 80 logical cpus. HT is enabled in the BIOS. &lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;40 cores without HT&lt;/STRONG&gt;&lt;/EM&gt;. That is 40 logical cpus. HT is disabled in the BIOS. &lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;20 cores with HT&lt;/STRONG&gt;&lt;/EM&gt;. That is 40 logical cpus. HT is enabled in the BIOS.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;&lt;STRONG&gt;20 cores without HT&lt;/STRONG&gt;&lt;/EM&gt;. That is 20 logical cpus. HT is disabled in the BIOS.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The following chart shows the results when 200 simulated users are driving the workload concurrently. Note that with 200 users, all the processors on this test system are pushed to ~100%.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/linchi_shea/hyperthreding_OLTP_queries_38692D15.png"&gt;&lt;IMG style="BORDER-BOTTOM:0px;BORDER-LEFT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;" title=hyperthreding_OLTP_queries border=0 alt=hyperthreding_OLTP_queries src="http://sqlblog.com/blogs/linchi_shea/hyperthreding_OLTP_queries_thumb_3A3982DC.png" width=602 height=438&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Compared with the results for the reporting queries (see &lt;A href="http://sqlblog.com/blogs/linchi_shea/archive/2012/01/05/performance-impact-hyperthreading-for-reporting-queries.aspx"&gt;the previous post&lt;/A&gt;), the performance gain from enabling HT on the 40 cores is very much more marginal with this OLTP benchmark. We see an increase of about 5% from ~7900 batch requests per second to ~8300 batch requests per second. Enabling HT on the 20 cores produces an improvement of similar magnitude (about 7.5%).&lt;/P&gt;
&lt;P&gt;Going from 20 cores with HT to 40 cores without HT, however, gives the OLTP queries a dramatic throughput gain of about 67% from ~4730 batch requests per second to ~7900 batch requests per second. We see similar behavior with the reporting queries. Knowing how HT works, I think it is intuitive we expect a big gain, whether or not it should be 67%.&lt;/P&gt;
&lt;P&gt;So for both the reporting queries and the OLTP queries that I have tested, the hyperthreading results are positive. So far so good!&lt;/P&gt;</description></item><item><title>How Microsoft helps you NOT break your Windows Azure Application: Storage Services Versioning</title><link>http://sqlblog.com/blogs/buck_woody/archive/2011/12/06/how-microsoft-helps-you-not-break-your-windows-azure-application-storage-services-versioning.aspx</link><pubDate>Tue, 06 Dec 2011 14:42:57 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40161</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;&lt;font size="2"&gt;One of the advantages of using Windows Azure to run your code is that you don’t have to constantly manage upgrades on your platform. While that’s a big advantage indeed, it immediately brings up the question - how do the upgrades happen? Microsoft upgrades the Azure platform in periodic increments, and the components that are affected are documented. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;This brings up another question - upgrades mean change, and change can sometimes alter the way you might implement a feature. What if you have taken a dependency on some feature in your code that has been altered by an upgrade? Windows Azure does have an Application Lifecycle Management (ALM) Process, which I’ll reference at the end of this post. But beyond that, there are some features we’ve put into place that will help you manage many of these changes. One of those is being able to set the version of storage features you would like your code to use. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Windows Azure is made up of three main component areas: Computing, Storage and a group of features called the Application Fabric. You can use these components together or separately, depending on what you would like your application to do. In this post I’ll deal with the version control in the storage subsystem - in other posts I’ll explain how to track and in some cases control the versions of the other components you work with.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;When you send a request to a Windows Azure resource, you’re actually using a &lt;a href="http://en.wikipedia.org/wiki/REST" target="_blank"&gt;REST&lt;/a&gt; call. That’s a three-part call to the system that has a request (called a URI), a header, and a body of code you want to send. So a typical call, such as to a table, might look like this example, which changes the properties of a Blob: &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;URI&lt;/strong&gt;:       &lt;br /&gt;&lt;font color="#0000ff"&gt;PUT http://myaccount.table.core.windows.net/?restype=service&amp;amp;comp=properties HTTP/1.1&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Header&lt;/strong&gt;:       &lt;br /&gt;&lt;font color="#0000ff"&gt;&lt;font style="background-color:#ffff00;"&gt;x-ms-version: 2011-08-18&lt;/font&gt;        &lt;br /&gt;x-ms-date: Tue, 30 Aug 2011 04:28:19 GMT        &lt;br /&gt;Authorization: SharedKey        &lt;br /&gt;myaccount:Z1lTLDwtq5o1UYQluucdsXk6/iB7YxEu0m6VofAEkUE=        &lt;br /&gt;Host: myaccount.table.core.windows.net&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;Body&lt;/strong&gt;:      &lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;       &lt;br /&gt;&amp;lt;StorageServiceProperties&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Logging&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Version&amp;gt;1.0&amp;lt;/Version&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Delete&amp;gt;true&amp;lt;/Delete&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Read&amp;gt;false&amp;lt;/Read&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Write&amp;gt;true&amp;lt;/Write&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RetentionPolicy&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Enabled&amp;gt;true&amp;lt;/Enabled&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Days&amp;gt;7&amp;lt;/Days&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/RetentionPolicy&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Logging&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Metrics&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Version&amp;gt;1.0&amp;lt;/Version&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Enabled&amp;gt;true&amp;lt;/Enabled&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;IncludeAPIs&amp;gt;false&amp;lt;/IncludeAPIs&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;RetentionPolicy&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Enabled&amp;gt;true&amp;lt;/Enabled&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Days&amp;gt;7&amp;lt;/Days&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/RetentionPolicy&amp;gt;        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Metrics&amp;gt;        &lt;br /&gt;&amp;lt;/StorageServiceProperties&amp;gt;        &lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;em&gt;(&lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh452240.aspx" target="_blank"&gt;&lt;em&gt;Source&lt;/em&gt;&lt;/a&gt;&lt;em&gt; of this code)&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;You can see that I’ve highlighted a portion of the header block - that’s where you set the version of the Storage Services you would like to use. You can find a list of the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/dd894041.aspx" target="_blank"&gt;features introduced in each version here&lt;/a&gt;. &lt;/font&gt;&lt;font size="2"&gt;It’s not a requirement of adding that element to the header, but it’s best practices to do so. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;You don’t have to use REST calls directly, however. It’s more common to use the API in the Software Development Kit to just change the property in your IDE environment - the setting you’re looking for there is the &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh343266.aspx"&gt;Set Storage Service Properties&lt;/a&gt; call. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Interestingly, rather than a breaking change you might run into an unexpected behavior if you are not aware of these parameters. In some code I recently reviewed a newer feature from the storage system failed when it was called. On inspection I found that the developer had used an older codeblock from a previous version of the storage system - he was not aware you can set the version of storage in the call. We changed the header to the latest version, and everything worked as expected. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;The Storage Services Versioning and the changes for each version: &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/dd894041.aspx"&gt;&lt;u&gt;&lt;font color="#4f81bd" size="2" face="Arial"&gt;http://msdn.microsoft.com/en-us/library/windowsazure/dd894041.aspx&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;font color="#000000" face="Arial"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&lt;font color="#000000" size="2" face="Arial"&gt;Windows Azure Application Lifecycle Management: &lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&lt;font color="#000000" size="2" face="Arial"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff803362.aspx"&gt;http://msdn.microsoft.com/en-us/library/ff803362.aspx&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&lt;font color="#000000" size="2" face="Arial"&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Azure-Jump-Start-03-Windows-Azure-Lifecycle-Part-1"&gt;http://channel9.msdn.com/posts/Windows-Azure-Jump-Start-03-Windows-Azure-Lifecycle-Part-1&lt;/a&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&lt;a href="http://channel9.msdn.com/Events/TechEd/Australia/Tech-Ed-Australia-2011/COS201"&gt;http://channel9.msdn.com/Events/TechEd/Australia/Tech-Ed-Australia-2011/COS201&lt;/a&gt;&amp;#160;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:'Calibri','sans-serif';font-size:11pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa;"&gt;&amp;#160;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Why generalizations are dangerous</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/09/15/why-generalizations-are-dangerous.aspx</link><pubDate>Thu, 15 Sep 2011 23:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38491</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;A couple of years ago, John Sansom wrote a blog post comparing the performance of two different ways to get the maximum value from a column: MAX() and TOP (1).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://www.johnsansom.com/performance-comparison-of-select-top-1-verses-max/" title="http://www.johnsansom.com/performance-comparison-of-select-top-1-verses-max/" target="_blank"&gt;http://www.johnsansom.com/performance-comparison-of-select-top-1-verses-max/&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the conclusion, he states:&amp;nbsp; &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div style="padding:10px 20px;"&gt;&lt;i&gt;When a clustered index is present on the table &amp;amp; column that is 
to be selected, both the MAX() operator and the query (SELECT TOP 1 
ColumnName order by ColumnName) have almost identical performance.
&lt;/i&gt;
&lt;p&gt;&lt;i&gt;When there is no clustered index on the table &amp;amp; column to be queried, the MAX() operator offers the better performance.&lt;/i&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now for this specific case, that is quite true. But I find it alarming when people take his conclusion and believe it applies to every single scenario - so much so that they make policy decisions around prohibiting the use of TOP 1 in all situations (regardless of whether the ordering is on an indexed column, a non-indexed column, or even an aggregate). This isn't John's fault, of course. It's just the nature of people who believe that something they see once means it applies everywhere (SELECT without ORDER BY, anyone?).&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Recently a user asked the community to help them re-write a query that was currently using TOP 1 - not because the query was slow or produced the wrong results, but because they were told they could no longer use TOP 1. When asked why, they simply pointed at John's blog post above, and were going with the theory that TOP 1 is always slower and it must be eradicated from their codebase. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;Not being a big fan of generalizations, I tried to explain that John's situation was not quite the same - for one he was getting the max value from a single column, whereas the query in question actually wanted the max from an aggregate in a subquery - but they didn't seem to want to have anything to do with it. So, naturally, I set out to run some tests myself. Here is the query that was subject to refactoring - essentially they wanted the team name with the highest number of members:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;t.name&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;team &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;t&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER JOIN &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;SELECT TOP &lt;/font&gt;&lt;font color="black"&gt;1 &lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(*) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;membercount&lt;/font&gt;&lt;font color="gray"&gt;,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;teamID&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;dbo.teammember&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;GROUP BY &lt;/font&gt;&lt;font color="black"&gt;teamID&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ORDER BY &lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(*) &lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;team_with_most_members&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;t.id &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;team_with_most_members.teamID&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;There were two other solutions offered (well, three, but one didn't work). One was from me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;t.name &lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;rn &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;ROW_NUMBER&lt;/font&gt;&lt;font color="gray"&gt;() &lt;/font&gt;&lt;font color="blue"&gt;OVER &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;ORDER BY &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&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;&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;,&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;&lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(*)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember &lt;/font&gt;&lt;font color="blue"&gt;GROUP BY &lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;x&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;y&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER JOIN &lt;/font&gt;&lt;font color="black"&gt;dbo.Team &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;t&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;y.TeamID &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;t.ID&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;y.rn &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;
 
&lt;p&gt;And one was from Wil:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;t.name &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;team &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;t &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;JOIN &lt;/font&gt;&lt;font color="black"&gt;teammember &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;tm &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;tm.teamID &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;t.ID &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GROUP BY &lt;/font&gt;&lt;font color="black"&gt;t.Name&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;HAVING &lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;tm.id&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="magenta"&gt;MAX&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;members&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt; &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;id&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="black"&gt;members &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;teammember &lt;/font&gt;&lt;font color="blue"&gt;GROUP BY &lt;/font&gt;&lt;font color="black"&gt;teamid&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;sub&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt; 
&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

So to compare the three options, I first created some sample tables. The first was the main Team table:&lt;br&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;dbo.Team&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ID &lt;/font&gt;&lt;font color="blue"&gt;INT PRIMARY KEY CLUSTERED&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;Name &lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;));&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;Then I created two versions of the TeamMember table, one with a clustered index on the TeamID column, and one with a non-clustered index: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_A&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ID &lt;/font&gt;&lt;font color="blue"&gt;INT IDENTITY&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;PRIMARY KEY NONCLUSTERED&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;TeamID &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;Name &lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;));&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE CLUSTERED INDEX &lt;/font&gt;&lt;font color="black"&gt;x &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_A&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_B&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;ID &lt;/font&gt;&lt;font color="blue"&gt;INT IDENTITY&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;PRIMARY KEY CLUSTERED&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;TeamID &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;Name &lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;));&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE INDEX &lt;/font&gt;&lt;font color="black"&gt;x &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_B&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;To populate them with a reasonable volume of data, I performed some creative queries against sys.objects. First I populated a table variable with a group of random rows based on object_id, with the first column being the TeamID, and the second column being the number of rows that I would insert into the TeamMember tables:

&lt;/p&gt;&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE &lt;/font&gt;&lt;font color="#434343"&gt;@src &lt;/font&gt;&lt;font color="blue"&gt;TABLE&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;TeamID &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;TeamSize &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;;&lt;/font&gt;&lt;font color="blue"&gt;WITH &lt;/font&gt;&lt;font color="black"&gt;x&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;o&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;c&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[object_id] &lt;/font&gt;&lt;font color="gray"&gt;% &lt;/font&gt;&lt;font color="black"&gt;10000&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;[object_id] &lt;/font&gt;&lt;font color="gray"&gt;/ &lt;/font&gt;&lt;font color="black"&gt;15000.0&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="black"&gt;1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;sys.objects&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INSERT &lt;/font&gt;&lt;font color="#434343"&gt;@src &lt;/font&gt;&lt;font color="blue"&gt;SELECT TOP &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;30&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="black"&gt;o&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;c&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;x &lt;/font&gt;&lt;font color="blue"&gt;WHERE &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="gray"&gt;&amp;gt; &lt;/font&gt;&lt;font color="black"&gt;0&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ORDER BY &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;This created 30 values like this (the last several rows yield c = 1): &lt;br&gt;&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a.png" border="1" height="271" width="144"&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now that I had a set of 30 teams to create, I could use a cursor and a while loop (fun, fun) to populate the TeamMember tables. Could I have used a numbers table and done a cross join or something to avoid the loop? Sure, but this was easy enough and it is not exactly production code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="#434343"&gt;@TeamSize &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="#434343"&gt;@i &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DECLARE &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="blue"&gt;CURSOR LOCAL STATIC FORWARD_ONLY READ_ONLY&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FOR SELECT &lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;TeamSize&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="#434343"&gt;@src&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;OPEN &lt;/font&gt;&lt;font color="black"&gt;c&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FETCH NEXT &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="blue"&gt;INTO &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="#434343"&gt;@TeamSize&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHILE &lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;@@FETCH_STATUS&lt;/font&gt;&lt;/font&gt;&lt;font color="#434343"&gt; &lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;0&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SET &lt;/font&gt;&lt;font color="#434343"&gt;@i &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHILE &lt;/font&gt;&lt;font color="#434343"&gt;@i &lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;= &lt;/font&gt;&lt;font color="#434343"&gt;@TeamSize&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;INSERT &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_A&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;Name&lt;/font&gt;&lt;font color="gray"&gt;)&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;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INSERT &lt;/font&gt;&lt;font color="black"&gt;dbo.TeamMember_B&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;Name&lt;/font&gt;&lt;font color="gray"&gt;)&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;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;), &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SET &lt;/font&gt;&lt;font color="#434343"&gt;@i &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;+=&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FETCH NEXT&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;c &lt;/font&gt;&lt;font color="blue"&gt;INTO &lt;/font&gt;&lt;font color="#434343"&gt;@TeamID&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="#434343"&gt;@TeamSize&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;br&gt;CLOSE &lt;/font&gt;&lt;font color="black"&gt;c&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DEALLOCATE &lt;/font&gt;&lt;font color="black"&gt;c&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;So a quick count showed we had 30 rows in the Team table, and about 1.3 million rows in the TeamMember tables (with individual teams ranging from one row to 140,000 rows). &lt;/p&gt;

&lt;p&gt;Now we could put our three queries to the test! I opened up my trusty copy of &lt;a href="http://sqlsentry.net/plan-explorer/sql-server-query-view.asp" title="http://sqlsentry.net/plan-explorer/sql-server-query-view.asp" target="_blank"&gt;SQL Sentry Plan Explorer&lt;/a&gt; and pasted the three queries into the Command Text pane. I clicked the "Actual Plan" button, which goes to the server, runs the query, retrieves the actual plan, and discards the results. First I ran it for the A table (clustered index on TeamID), and these were the results from the Statements Tree tab:&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_comp.png" border="1" height="105" width="654"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Similar results for the B table (the one with just a non-clustered index on the TeamID column):&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_comp.png" border="1" height="103" width="642"&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;In both cases, Wil's solution came out at about twice the cost as the original query (and my proposed replacement). You can see where the doubling comes in from Wil's graphical plan (an extra scan), compared to the other two (the screen shots are presented in the same order as the 6 rows shown in the Statements Tree rows above - click on any to embiggen):&lt;br&gt;&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&amp;nbsp;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_orig.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_orig.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_orig.png" border="1" height="105" width="624"&gt;&lt;/a&gt;&lt;br&gt;Original - TeamMember_A&lt;br&gt;&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_aaron.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_aaron.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_aaron.png" border="1" height="104" width="813"&gt;&lt;/a&gt; &lt;br&gt;Aaron - TeamMember_A&lt;br&gt;&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_wil.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_wil.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_a_wil.png" border="1" height="154" width="502"&gt;&lt;/a&gt;&lt;br&gt;Wil - TeamMember_A&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_orig.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_orig.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_orig.png" border="1" height="103" width="381"&gt;&lt;/a&gt;&lt;br&gt;Original - TeamMember_B &lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_aaron.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_aaron.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_aaron.png" border="1" height="106" width="610"&gt;&lt;/a&gt;&lt;br&gt;Aaron - TeamMember_B&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;a href="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_wil.png" title="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_wil.png" target="_blank"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/09/so_1_b_wil.png" border="1" height="145" width="619"&gt;&lt;/a&gt;&lt;br&gt;Wil - TeamMember_B &lt;br&gt;&lt;/p&gt;

&lt;p&gt;I tried running the tests again with parallelism off, and while the 
plans looked a little different, the overall results were nearly 
identical (~50/25/25 split). &lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;span style="font-weight:bold;"&gt;Conclusion&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Generalizations are dangerous. Even if a situation looks similar to the one you've got, you owe it to yourself to test. Especially in a case where you've been asked to change your code to improve performance, and you've actually accepted a solution that performs worse.&lt;br&gt;&lt;/p&gt;



&lt;p&gt;&lt;span style="font-style:italic;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Plan for Diagnostics in Cloud Computing From the Git-Go</title><link>http://sqlblog.com/blogs/buck_woody/archive/2011/09/06/plan-for-diagnostics-in-cloud-computing-from-the-git-go.aspx</link><pubDate>Tue, 06 Sep 2011 13:11:22 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38295</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;“Git-Go” is something we say in the South that means “right at the start”. I’ve seen several applications for on-premise systems that don’t have much in the way of diagnostics - the developers rely on a debugger, the event logs on the server and client workstation, and most of all, the ability to watch the system from end-to-end. &lt;/p&gt;  &lt;p&gt;This approach is a mistake for an on-premise system, and it’s definitely a problem for a distributed architecture. You simply do not own all of the components from end to end in a cloud environment, nor are you always able to attach a debugger or other remote monitoring tools to the various areas within the code path. So you need to make sure that from the very outset of your design that you build in diagnostics. My personal preference is to build a system such that a control file turns on deeper information gathering from the system, up to a minimal level.&lt;/p&gt;  &lt;p&gt;When I do that, I set a high level of logging, a medium level, and a moderate level. I normally use the deepest level of information during the testing and acceptance phase of the deployment, then switch to moderate and then the least level of information gathering. Also in my design I often set an error condition to begin gathering the deeper information along with the exception, where possible.&lt;/p&gt;  &lt;p&gt;There are decisions you need to make as to where to store the diagnostics (many operations in the cloud cost money), how often you collect them, and so on. You can get a quick overview on using the diagnostics that come with Windows Azure here: &lt;a href="http://www.azuresupport.com/2010/03/getting-started-with-windows-azure-diagnostics-and-monitoring/"&gt;http://www.azuresupport.com/2010/03/getting-started-with-windows-azure-diagnostics-and-monitoring/&lt;/a&gt; This is where you should start first. More detail on that: &lt;a href="http://msdn.microsoft.com/en-us/library/gg433048.aspx"&gt;http://msdn.microsoft.com/en-us/library/gg433048.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;My friend Dave Pallman has a great tool he’s released for free: &lt;a href="http://davidpallmann.blogspot.com/2009/03/azure-application-monitor-now-on.html"&gt;http://davidpallmann.blogspot.com/2009/03/azure-application-monitor-now-on.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If the issue is in storage apps: &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83"&gt;http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/d84ba34b-b0e0-4961-a167-bbe7618beb83&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you have System Center, this is the quickest and easiest way to implement the monitoring – really handy: &lt;a href="http://pinpoint.microsoft.com/en-us/applications/windows-azure-application-monitoring-management-pack-release-candidate-12884907699"&gt;http://pinpoint.microsoft.com/en-us/applications/windows-azure-application-monitoring-management-pack-release-candidate-12884907699&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Performance impact: The cost of doing small lookups in a large batch update</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2011/04/04/performance-impact-the-cost-of-doing-small-lookups-in-a-large-batch.aspx</link><pubDate>Mon, 04 Apr 2011 18:34:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34640</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Lookup tables are widely used in database applications for good reasons. Usually, a lookup table&amp;nbsp;has a&amp;nbsp;small number of rows and looking it up with a join is fast, especially when the table is already cached. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Recently, I needed to update every row in many relatively large tables, each of which was identically structured, had ~25 million rows, and was ~30GB in size. The tables were denormalized to include both a lookup index column (i.e. CategoryID, which was an integer) and the corresponding lookup value column (i.e. CategoryName, which was a char(50)). The batch update I was performing was to ensure that the CategoryName column of these tables had the correct matching the value. The CategoryID to CategoryName mapping was defined in a small lookup table, CategoryLookup, with 10 rows.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;"&gt;&lt;FONT face=Calibri&gt;Question&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;What would be the most efficient method to perform this batch update?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;"&gt;&lt;FONT face=Calibri&gt;Three lookup methods&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;For the batch update scenario described above, you have three&amp;nbsp;alternatives to lookup the CategpryName values (assume that the table to be updated is called Transactions):&lt;/FONT&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP:0in;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 10pt;mso-list:l0 level1 lfo1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;Method 1&lt;/I&gt;—The inline CASE method, which performs an inline lookup with a CASE expression in the UPDATE statement. Okay, this is not really a lookup. But this method provides a baseline for comparison.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.5in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;UPDATE Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET CategoryName = CASE &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 1 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc1'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 2 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc2'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 3 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc3'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 4 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc4'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 5 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc5'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 6 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc6'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 7 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc7'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 8 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc8'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 9 &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;then 'abc9'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&lt;/SPAN&gt;when CategoryID = 10 then 'abc10'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;mso-list:l0 level1 lfo1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL style="MARGIN-TOP:0in;"&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 10pt;mso-list:l0 level1 lfo1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;Method 2&lt;/I&gt;—The JOIN method, which relies on joining the Transactions table and the CategoryLookup table to do the lookup.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;UPDATE t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET t1.CategoryName = t2.CategoryName&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;FROM Transactions t1 JOIN CategoryLookup t2 &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ON t1.CategoryID = t2.CategoryID&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;mso-list:l0 level1 lfo1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI class=MsoNormal style="MARGIN:0in 0in 10pt;mso-list:l0 level1 lfo1;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;Method 3&lt;/I&gt;—The subquery method, which&amp;nbsp;does a lookup with a subquery. Clearly, there is a join in the subquery.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;UPDATE Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET CategoryName = &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(SELECT CategoryLookup.CategoryName&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;FROM CategoryLookup &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt 0.25in;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;WHERE CategoryLookup.CategoryID=Transactions.CategoryID )&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;You can also do the lookup with a scalar function. But it’s so horrifically inefficient that you should not seriously consider it. It’s not interesting to include in this discussion. In addition, you could do the lookup with an inline&amp;nbsp;table valued function, which has a similar performance profile as that of the inline CASE method.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;It should be highlighted that method 2 (the JOIN method) and method 3 (the Subquery method) are not semantically identical. For instance, if the Transactions table has a CategoryID value that is not present in the CategoryLookup table, the Subquery method will, if permitted,&amp;nbsp;set the CategoryName column to NULL,&amp;nbsp;or the update will fail if NULL is not permitted, whereas the JOIN method will leave the CategoryName value unchanged. For the scenario we are interested in, the results of these two methods are identical.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;All the CategorID values in the Transactions table are also in the CategoryLookup table and the mapping from CategoryID to CategoryName in the CategoryLookup table is one to one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I ran a series of controlled tests that mimicked the update scenario described previously. To keep the tests more manageable, I used a smaller and artificially created Transactions table that had 5,000,000 rows and was ~5GB in size. You can find the DDLs and the test script at the bottom of this post. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;"&gt;&lt;FONT face=Calibri&gt;Test results and practical implications&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I made sure that the results shown below were&amp;nbsp;stable in that (1) they were taken from 50 repeated tests with a small number of outliers thrown out, and (2) the remaining results were inspected and made sure that the variances were relatively small among them and the values exhibited a consistent pattern.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://sqlblog.com/blogs/linchi_shea/attachment/34640.ashx"&gt; &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Clearly, if you do a massive number of lookups (like what I did in this test), the cumulative cost can be quite visible. In fact, in this test using an inline CASE expression was more than twice as fast as lookups using either a subquery or a straight join. &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;As the number of rows increases, you can expect to see this difference (or the cost of doing lookups) grow more prominent. So, if you are doing a very large batch update, it’s definitely worth replacing the table lookups with an inline CASE expression for better performance.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The difference between the CASE method and the table lookups (either the Subquery method or the JOIN method) remained stable across different test environments. But the difference between the Subquery method and the JOIN method was more subtle. In fact, if you run the same test in a different environment, you may&amp;nbsp;see&amp;nbsp;different relative performance between them. In some environments,&amp;nbsp;the Subquery method can perform significantly better than the JOIN method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Although there was a significant performance penalty when using Subquery or JOIN lookups in a massive update, this does not mean you should&amp;nbsp;jettison using lookups in your individual transactions. Because the marginal cost of doing an individual lookup is infinitesimally small compared to many other performance-related factors, you’d lose much more&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;in terms of code reuse, flexibility, and so on if you start to embed ‘lookups’ inline. To &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;emphasize, note that the difference between the CASE method and the Subquery method in the test was ~34 seconds. Divide 34 seconds by the 5,000,000 lookups the update did, we get 6.8 microseconds&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;as the marginal cost of an individual lookup.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="mso-no-proof:yes;"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;There is no surprise that avoiding a massive number of&amp;nbsp;table lookups could give you better performance. But it’s still good to be able to appreciate it with&amp;nbsp;some concrete numbers. My update of&amp;nbsp;all those 25-million-row tables mentioned at the beginning of this post took more than 10 hours to complete and I used the subquery method. Had I had the results reported here, I could have finished the same update process in five hours. That would have been a very nice saving!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;"&gt;&lt;FONT face=Calibri&gt;Test setup&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The lookup DDL and data:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;drop table CategoryLookup&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;create table CategoryLookup(CategoryID int, CategoryName char(20))&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;with tmp(a, b) as (&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;select 1, 'abc' + cast(1 as varchar(5))&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;union all&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;select a+1, 'abc' + cast(a+1 as varchar(5))&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;from tmp&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where a &amp;lt; 10&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;insert CategoryLookup&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;select * from tmp&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;create clustered index cix_CategoryLookup on CategoryLookup(CategoryID)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 10pt;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The Transactions test table DDL and data:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;drop table Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;create table Transactions(CategoryID int, &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CategoryName char(50),&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;filler char(1000))&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;set nocount on&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;declare @i int&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;set @i = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;begin tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;while @i &amp;lt;= 5000000&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;insert Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;select @i % 10 + 1, 'abc', 'filler'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if @i % 100000 = 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;commit tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;begin tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set @i = @i + 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;if @@trancount &amp;gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;commit tran&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;sp_spaceused Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;create clustered index cix_Transactions on Transactions(CategoryID)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;drop table test_log – this tale is used to log the test times&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;create table test_log (&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Name&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;varchar(50),&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Num&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;StartTime&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;datetime,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;EndTime&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;datetime NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;)&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The test script:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;set nocount on&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;declare @dt datetime,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@i int&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;set @i = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;while @i &amp;lt; 20 -- run the test 20 times&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set @dt = getdate() &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;insert test_log select 'CASE method', 10, @dt, NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;update Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set CategoryName = case &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 1&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc1'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 2&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc2'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 3&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc3'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 4&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc4'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 5&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc5'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 6&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc6'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 7&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc7'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 8&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc8'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 9&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;then 'abc9'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;when CategoryID = 10 then 'abc10'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&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; &lt;/SPAN&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;update test_log&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set EndTime = getdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where StartTime = @dt&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;set @dt = getdate() &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;insert test_log select 'Subquery method', 10, @dt, NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;update Transactions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set CategoryName = &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(select CategoryLookup.CategoryName &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;from CategoryLookup &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where CategoryLookup.CategoryID= Transactions.CategoryID )&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;update test_log&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set EndTime = getdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where StartTime = @dt&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;set @dt = getdate() &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;insert test_log select 'JOIN method', 10, @dt, NULL&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;update t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set t1.CategoryName = t2.CategoryName&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;from Transactions t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;join CategoryLookup t2 on t1.CategoryID = t2.CategoryID&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;update test_log&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;set EndTime = getdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where StartTime = @dt&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;set @i = @i +1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#f2f2f2;MARGIN:0in 0in 10pt;mso-background-themecolor:background1;mso-background-themeshade:242;"&gt;&lt;FONT size=3&gt;&lt;SPAN style="COLOR:black;FONT-FAMILY:'Courier New';mso-no-proof:yes;mso-themecolor:text1;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="COLOR:black;mso-themecolor:text1;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The reported results were obtained on&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;a DL585 G1 with 64GB of RAM and eight 2.6GHz cores, running Windows Server Enterprise 2003 and SQL Server 2008 SP2 Enterprise x64 Edition. 50GB was allocated to the SQL Server instance.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>Linked servers: how long do they stay connected?</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2011/03/31/linked-servers-how-long-do-they-stay-connected.aspx</link><pubDate>Fri, 01 Apr 2011 00:36:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34537</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I was looking at some of my old notes on linked servers and found a tidbit on how the linked server connections are managed by SQL Server. I'm posting it here because&amp;nbsp;I don’t think the information is widely known.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;When you make a linked server call from a SQL Server instance (say ServerA) to another SQL Server instance (say ServerB) over Microsoft Native Client OLEDB Provider, SQL Server on ServerA acts as a client to the instance on ServerB and will open or reuse a connection to ServerB. That connection will be managed by the SQL Server instance on ServerA.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;If you check on ServerB with the following query, you should see that connection from ServerA (if it's still there):&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 10pt;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;And if no linked server calls from ServerA is using the connection, its status would be ‘dormant’.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The question is, “how long will ServerA keep the connection alive if no call&amp;nbsp;is using it? And can you configure&amp;nbsp;it?”&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I can’t find any official documentation to answer these two questions. But my own tests appear to yield a consistent answer to the first question. That is, a dormant SQL Server linked server connection will stay for about 4~5 minutes, and will be closed after that. All my attempts to see if this number is configurable suggest that the answer is negative. If anyone knows a more authoritative answer, please post it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Here is&amp;nbsp;a simple&amp;nbsp;test to determine how long a dormant connection stays alive.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;On ServerB, use the&amp;nbsp;previous query to ensure that there is no&amp;nbsp;linked server connection from ServerA. If there is, kill the connection and ensure ServerA does not open a new one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;On ServerB, run this script:&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;declare @dt datetime&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;while not exists (select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;waitfor delay '00:00:01'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;set @dt = getdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;while exists (select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;waitfor delay '00:00:01'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select 'Duration' = datediff(second, @dt, getdate())&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;FONT face=Calibri size=3&gt;Go to ServerA and run the next script:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select * from openquery(ServerB, 'select @@servername')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;&lt;BR&gt;I have been consistently getting the Duration values between ~260 seconds and ~300 seconds, which is about 4~5 minutes. &lt;/FONT&gt;&lt;FONT face=Calibri size=3&gt;If you have any test numbers of your own &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;or run this test, please post your findings.&lt;/FONT&gt;&lt;/P&gt;</description></item></channel></rss>