<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>T-SQL</title>
        <link>http://weblogs.sqlteam.com/joew/category/271.aspx</link>
        <description>Transact-SQL programming tips and tricks</description>
        <language>en-US</language>
        <copyright>Joe Webb</copyright>
        <managingEditor>joew@webbtechsolutions.com</managingEditor>
        <generator>Subtext Version 1.9.4.0</generator>
        <item>
            <title>SQLTeach - Writing better queries presentation</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/05/15/60600.aspx</link>
            <description>&lt;a href="http://www.webbtechsolutions.com/downloads/SQLTeach_Writing_Better_Queries_2008-05-14.zip"&gt;Here's a presentation&lt;/a&gt; that I gave yesterday afternoon at &lt;a href="http://www.devteach.com"&gt;DevTeach/SQLTeach&lt;/a&gt;. It's called Tips &amp;amp; Tricks for Writing Better Queries. It's very similar to the presentation I gave a month or so ago at the &lt;a href="http://nashville.sqlpass.org"&gt;Nashville SQL Server User Group&lt;/a&gt; meeting. &lt;br /&gt;
&lt;br /&gt;
To everyone who attended the session - thanks for spending a part of your day with me. I hope it was worth your while. Please feel free to email me if you have any additional questions or comments. And please remember to login to your SQLTeach account and submit your session evals. &lt;br /&gt;
&lt;br /&gt;
Cheers! &lt;br /&gt;
&lt;br /&gt;
Joe &lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f05%2f15%2f60600.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f05%2f15%2f60600.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60600.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/05/15/60600.aspx</guid>
            <pubDate>Thu, 15 May 2008 14:37:38 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60600.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/05/15/60600.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60600.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Finding Notification Services Instances</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/05/06/60589.aspx</link>
            <description>&lt;p&gt;As most you already know, Notification Services is not part of Microsoft SQL Server 2008. I think this is a shame since SSNS is really a great product. It may be rather complex at first glance, but it's a great product nonetheless. I'll probably devote a blog to it's abrupt deprecation at some point in the future.  &lt;/p&gt;
&lt;p&gt;In the meantime, if you're preparing to upgrade to SQL Server 2008, you should verify that you don't have any rogue SSNS instances running on any of your servers. I hope your environment is more controlled than that, but I've seen more than one shop where change control was, well in a word, uncontrolled.  &lt;/p&gt;
&lt;p&gt;So, how can you tell if a server has a SSNS installed on it? Run the following query in the msdb database. It'll list all SSNS instances installed on that SQL Server instance. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;br /&gt;     InstanceName&lt;br /&gt;    ,DatabaseName&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;     msdb.NS90.NSInstances &lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
]]&gt;&lt;/style&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Cheers!  &lt;/p&gt;
&lt;p&gt;Joe &lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f05%2f06%2f60589.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f05%2f06%2f60589.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60589.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/05/06/60589.aspx</guid>
            <pubDate>Tue, 06 May 2008 20:31:03 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60589.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/05/06/60589.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60589.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Getting column information using T-SQL</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/04/27/60574.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Ocassionally, I see a question in the MSDN Forums where someone wants to know how to retrieve a list of column information for a table using only T-SQL.  &lt;/p&gt;
&lt;p&gt;Although there are several ways in which to approach this, I like the following method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;br /&gt;   ORDINAL_POSITION&lt;br /&gt;  ,COLUMN_NAME&lt;br /&gt;  ,DATA_TYPE&lt;br /&gt;  ,CHARACTER_MAXIMUM_LENGTH&lt;br /&gt;  ,IS_NULLABLE&lt;br /&gt;  ,COLUMN_DEFAULT&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   &lt;br /&gt;  INFORMATION_SCHEMA.COLUMNS &lt;span class="kwrd"&gt;&lt;br /&gt;WHERE&lt;/span&gt;   &lt;br /&gt;  TABLE_NAME = &lt;span class="str"&gt;'Product'&lt;/span&gt; &lt;br /&gt;&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; &lt;br /&gt;  ORDINAL_POSITION &lt;span class="kwrd"&gt;ASC&lt;/span&gt;; &lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;Do you have a different way of doing this that you'd like to share? If so, feel free to leave a comment, sharing your way and why you like it.  &lt;/p&gt;
&lt;p&gt;Cheers!  &lt;/p&gt;
&lt;p&gt;Joe &lt;/p&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f27%2f60574.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f27%2f60574.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60574.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/04/27/60574.aspx</guid>
            <pubDate>Sun, 27 Apr 2008 14:05:45 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60574.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/04/27/60574.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60574.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Tips &amp; tricks for writing better queries presentation</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/04/04/60561.aspx</link>
            <description>Thanks to all 60+ people who braved the flood warnings in Nashville to attend the SQL Server User Group meeting earlier today. I hope you found it to be worth your while. Some of your questions and comments at the end gave some some great ideas for future presentations. Thanks!&lt;br /&gt;
&lt;br /&gt;
And thanks to Quest and RHT for sponsoring our meeting meeting today. If your in the Nashville areas, I'd encourage you to come on out for our next meeting, most likely sometime in May. &lt;br /&gt;
&lt;br /&gt;
As promised, &lt;a target="_blank" href="http://nashville.sqlpass.org/Resources/tabid/265/Default.aspx"&gt;here's a link to the presentation materials&lt;/a&gt;, both the PowerPoint presentation and the demonstration code.&lt;br /&gt;
&lt;br /&gt;
Cheers! &lt;br /&gt;
&lt;br /&gt;
Joe&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f04%2f60561.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f04%2f60561.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60561.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/04/04/60561.aspx</guid>
            <pubDate>Fri, 04 Apr 2008 19:30:16 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60561.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/04/04/60561.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60561.aspx</wfw:commentRss>
        </item>
        <item>
            <title>What SQL Server service pack do I have installed?</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/04/01/60559.aspx</link>
            <description>&lt;p&gt;If you've used SQL Server for a while, you're probably familiar with the @@version function. Selecting the function in a query window produces the following results on my system.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/WhatSQLServerservicepackdoIhaveinstalled_BEB9/Version-2008-04-01_2.jpg"&gt;&lt;img width="400" height="246" border="0" style="border: 0px none ;" alt="Version-2008-04-01" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/WhatSQLServerservicepackdoIhaveinstalled_BEB9/Version-2008-04-01_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;From this, you can quickly determine that I'm running SQL Server 2005 Developer Edition version 9.00.3054.00 on an Intel X86 processor. It may also appear that I've installed SQL Server SP2, however that is rather misleading. The "Service Pack 2" text in the above image refers to the operating system, not the SQL Server system. &lt;/p&gt;
&lt;p&gt;To determine SQL Server's service pack level, use the built-in SERVERPROPERTY function with appropriate parameters - EDITION, PRODUCTLEVEL, and PRODUCTVERSION.&lt;/p&gt;
&lt;p&gt;For example the following queries produce the results shown in the image below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/WhatSQLServerservicepackdoIhaveinstalled_BEB9/Version2-2008-04-01_2.jpg"&gt;&lt;img width="450" height="199" border="0" style="border: 0px none ;" alt="Version2-2008-04-01" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/WhatSQLServerservicepackdoIhaveinstalled_BEB9/Version2-2008-04-01_thumb.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;From this, you can see that I am indeed running SQL Server 2005 Developer Edition updated with Service Pack 2.&lt;/p&gt;
&lt;p&gt;The SERVERPROPERTY function is part of SQL Server 2000 and greater. Prior to that, we had to resort to equating the product version to a service pack level. Here's a &lt;a href="http://support.microsoft.com/kb/321185" target="_blank"&gt;link to a KB article&lt;/a&gt; with more details for v7.0 and earlier.&lt;/p&gt;
&lt;p&gt;Cheers! &lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f01%2f60559.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f04%2f01%2f60559.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60559.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/04/01/60559.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 22:27:49 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60559.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/04/01/60559.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60559.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Real world DBA podcast</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/03/25/60553.aspx</link>
            <description>I recently worked with Buck Woody to turn one of my blog posts into a podcast. It's my first podcast! :) I recorded it about midnight one evening after everyone else in my family had retired for the evening. With the house so quiet, I didn't realize I was whispering until I heard it mixed with Buck's projecting and charismatic dialog. &lt;a target="_blank" href="http://blogs.msdn.com/buckwoody/archive/2008/03/14/real-world-dba-episode-3-does-join-order-matter.aspx"&gt;Here's a link to the podcast&lt;/a&gt;. I'd love to hear what you think and if you'd like to hear more of these. &lt;br /&gt;
&lt;br /&gt;
If you're not familiar with Buck Woody's work in the SQL Server community, I would encourage you to head on over to his blog site - &lt;a target="_blank" href="http://blogs.msdn.com/buckwoody/"&gt;http://blogs.msdn.com/buckwoody/&lt;/a&gt;. He's putting together some great content, a mix of traditional blog posts and podcasts, called the Real world DBA. Good stuff! &lt;br /&gt;
&lt;br /&gt;
Cheers!&lt;br /&gt;
&lt;br /&gt;
Joe&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f03%2f25%2f60553.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f03%2f25%2f60553.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60553.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/03/25/60553.aspx</guid>
            <pubDate>Tue, 25 Mar 2008 11:34:28 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60553.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/03/25/60553.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60553.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Does order matter in a JOIN clause?</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/02/29/60542.aspx</link>
            <description>&lt;p&gt;A very astute SQL Server professional and reader of this blog posed the following question in a comment to a prior posting entitled "&lt;a target="_blank" href="http://weblogs.sqlteam.com/joew/archive/2008/02/22/60527.aspx"&gt;Does the order of criteria the WHERE clause matter?&lt;/a&gt;" The comment, submitted through Plaxo Pulse, is not available outside the Pulse community so I've included it below since it's the genesis of today's post.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;"What if you were using join statements? Does it matter what order your columns are used in the ON statement? ~ Ariel M."&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There are several derivatives of the original question:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Does the order of tables referenced in the ON clause of the JOIN matter? &lt;/li&gt;
    &lt;li&gt;Does the order of tables referenced in the FROM clause matter? &lt;/li&gt;
    &lt;li&gt;Does the order of columns referenced in the ON clause of the JOIN matter when multiple columns are used in the JOIN? &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I'll address questions 2 and 3 in another post; for now let's consider the first question. To paraphrase and exemplify the question: Will the following two queries produce differing execution plans and thus varying performance? Or does the Query Optimizer take this into account as it analyzes a statement before choosing an execution plan? &lt;/p&gt;
&lt;pre class="csharpcode"&gt;--Query #1&lt;br /&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;br /&gt;     c.Customer_ID&lt;br /&gt;    ,c.Last_Name&lt;br /&gt;    ,c.First_Name&lt;br /&gt;    ,s.Order_ID&lt;br /&gt;    ,s.Order_Date&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;    dbo.Customers &lt;span class="kwrd"&gt;AS&lt;/span&gt; c &lt;span class="kwrd"&gt;JOIN&lt;/span&gt;&lt;br /&gt;    dbo.Sales_Orders &lt;span class="kwrd"&gt;AS&lt;/span&gt; s &lt;span class="kwrd"&gt;&lt;br /&gt;	ON&lt;/span&gt; s.Customer_ID = c.Customer_ID&lt;br /&gt;&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;--Query #2&lt;br /&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;br /&gt;     c.Customer_ID&lt;br /&gt;    ,c.Last_Name&lt;br /&gt;    ,c.First_Name&lt;br /&gt;    ,s.Order_ID&lt;br /&gt;    ,s.Order_Date&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;    dbo.Customers &lt;span class="kwrd"&gt;AS&lt;/span&gt; c &lt;span class="kwrd"&gt;JOIN&lt;/span&gt;&lt;br /&gt;    dbo.Sales_Orders &lt;span class="kwrd"&gt;AS&lt;/span&gt; s &lt;span class="kwrd"&gt;&lt;br /&gt;	ON&lt;/span&gt; c.Customer_ID = s.Customer_ID&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Notice that the only difference in the two queries lies in the ON clause of the JOIN. The first query references Sales then Customers while the second reverses the order. &lt;/p&gt;
&lt;p&gt;To answer this question, let's look at the execution plan as provided by SQL Server Management Studio. The first query produces the following execution plan. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoesordermatterinaJOINclause_74C5/JoinPerform1-2008-02-29_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="262" alt="JoinPerform1-2008-02-29" width="480" border="0" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoesordermatterinaJOINclause_74C5/JoinPerform1-2008-02-29_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;In this query, SQL Server has chosen a Clustered Index Scan of the Sales_Orders table and an Index Scan for the Customers table. The two tables are joined using a Hash Match Inner Join.&lt;/p&gt;
&lt;p&gt;Now, let's look at the execution plan for the second query.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoesordermatterinaJOINclause_74C5/JoinPerform2-2008-02-29_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="260" alt="JoinPerform2-2008-02-29" width="480" border="0" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoesordermatterinaJOINclause_74C5/JoinPerform2-2008-02-29_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Query #2 produced the exact same execution plan! So, we can conclude from this simple example that the order of tables referenced in the ON clause of a JOIN doesn't affect the performance of a query. &lt;/p&gt;
&lt;p&gt;As an aside, though, both execution plans use a Hash Match Inner Join. Generally speaking this is not the most efficient join type for SQL Server; Loop Join is much more efficient. When you see a Hash Join in a query execution plan, consider your indexes. A Hash Join is frequently an indicator of inefficient indexing. I'll delve more deeply into this in another post. &lt;/p&gt;
&lt;p&gt;Cheers! &lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f29%2f60542.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f29%2f60542.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60542.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/02/29/60542.aspx</guid>
            <pubDate>Fri, 29 Feb 2008 15:15:11 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60542.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/02/29/60542.aspx#feedback</comments>
            <slash:comments>13</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60542.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Does the order of criteria the WHERE clause matter?</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/02/22/60527.aspx</link>
            <description>&lt;p&gt;Recently, I demonstrated that the order of columns in a composite index greatly determines its usefulness. Microsoft SQL Server can efficiently resolve queries using a composite index if the search criteria includes the first column in the index. If the search criteria omits the first column and includes only subsequent columns, the index is of no use to SQL Server for resolving that query. To see the proof, &lt;a href="http://weblogs.sqlteam.com/joew/archive/2008/02/13/60510.aspx"&gt;refer to this post&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;The example I used in the prior post included the following query as a basis for the discussion. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;         &lt;br /&gt;	* &lt;span class="kwrd"&gt;&lt;br /&gt;FROM&lt;br /&gt;	&lt;/span&gt;Customers &lt;span class="kwrd"&gt;&lt;br /&gt;WHERE&lt;br /&gt;&lt;/span&gt;	Last_Name = &lt;span class="str"&gt;'smith'&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;br /&gt;&lt;/span&gt;	First_Name = &lt;span class="str"&gt;'Jake'&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;One reader noted the order of the search criteria in the WHERE clause and wondered if it has any impact on the applicability of a composite index. In other words, would the following query still make use of the composite index? &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;         &lt;br /&gt;	* &lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;         &lt;br /&gt;	Customers &lt;br /&gt;&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;         &lt;br /&gt;	First_Name = &lt;span class="str"&gt;'Jake'&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt;         &lt;br /&gt;	Last_Name = &lt;span class="str"&gt;'smith'&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Great observation! To answer that question, let's once again look at the query execution plan for the first query. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoestheorderofcriteriatheWHEREclausematt_89D3/WhereOrder1-2008-02-22_2.jpg"&gt;&lt;img width="240" height="117" border="0" style="border: 0px none ;" alt="WhereOrder1-2008-02-22" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoestheorderofcriteriatheWHEREclausematt_89D3/WhereOrder1-2008-02-22_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;From this execution plan, we can see that the query optimizer found the composite index named ix_Customer_Name to be useful in resolving the query. This is certainly to be expected since the order of search criteria in the WHERE clause exactly matched the order of columns in the composite index. &lt;/p&gt;
&lt;p&gt;In the second query, however, the order of columns in the search criteria in the WHERE clause is reversed as compared to the composite index. Let's look at the execution plan so see if that makes any difference to SQL Server.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoestheorderofcriteriatheWHEREclausematt_89D3/WhereOrder2-2008-02-22_2.jpg"&gt;&lt;img width="240" height="116" border="0" style="border: 0px none ;" alt="WhereOrder2-2008-02-22" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/DoestheorderofcriteriatheWHEREclausematt_89D3/WhereOrder2-2008-02-22_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;This query produced the exact same execution plan as the prior query. Why? &lt;/p&gt;
&lt;p&gt;Generally speaking, the order of criteria in the WHERE clause is evaluated and optimized by the query optimizer prior to creating an execution plan. This is good. However, I would encourage you to review the query execution plan for each query prior to putting it into production. You may have some unique expressions or circumstances in your scenario that may be the exception to this rule. &lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f22%2f60527.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f22%2f60527.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60527.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/02/22/60527.aspx</guid>
            <pubDate>Fri, 22 Feb 2008 16:37:03 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60527.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/02/22/60527.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60527.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Does the order of columns in an index matter?</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/02/13/60510.aspx</link>
            <description>&lt;p&gt;A single column index is fairly straightforward to understand. You may have heard it compared to the index in the back of a technical book. When you want to find some information in the book, say DBCC INPUTBUFFER, you turn to the index in the back of the book and look up DBCC INPUTBUFFER. The index doesn't actually contain the information on DBCC INPUTBUFFER, it has a pointer to the page in the book where the command is described. So, what do you do? You turn to that page and read all about how DBCC INPUTBUFFER may be used. This is a good analogy for a single column non-clustered index.&lt;/p&gt;
&lt;h3&gt;Composite Indexes&lt;/h3&gt;
&lt;p&gt;In Microsoft SQL Server, you can also create an index that contains more than one column. These are known as composite indexes. A good analogy for a composite index is the telephone book.&lt;/p&gt;
&lt;p&gt;A telephone book lists every individual in the area who has a publicly available telephone number. It's organized not by one column, but two: last name, first name. (Ignoring the middle initial that is sometimes listed but most often treated as an extension of the person's first name). If you wanted to look up someone in the telephone book, you'd first navigate to the last name and then the first name. For example to find Jake Smith, you'd first locate the Smiths, then within the Smiths, you'd find Jake. The same holds true for a composite SQL Server index.&lt;/p&gt;
&lt;p&gt;This is all good to know, but how does it really affect query resolution? &lt;/p&gt;
&lt;p&gt;Well, let's consider an example. Let's assume you have a Customers table as described below.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; Customers&lt;br /&gt;        (&lt;br /&gt;         Customer_ID &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;                         &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1,1)&lt;br /&gt;        ,Last_Name &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(20) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;        ,First_Name &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(20) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;        ,Email_Address &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(50) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;        )&lt;/pre&gt;
&lt;p&gt;It has a clustered index on Customer_ID and composite index on the Last_Name, First_Name columns as shown below.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; &lt;span class="kwrd"&gt;INDEX&lt;/span&gt; ix_Customer_ID &lt;br /&gt;	&lt;span class="kwrd"&gt;ON&lt;/span&gt; Customers(Customer_ID)&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;INDEX&lt;/span&gt; ix_Customer_Name &lt;br /&gt;	&lt;span class="kwrd"&gt;ON&lt;/span&gt; Customers(Last_Name, First_Name)&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;font face="Trebuchet MS"&gt;&lt;/font&gt; &lt;/pre&gt;
&lt;h3&gt;Finding a specific row&lt;/h3&gt;
&lt;p&gt;To find a specific row, we could execute the following query.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;&lt;br /&gt;        *&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;        Customers&lt;br /&gt;&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;&lt;br /&gt;        Last_Name = &lt;span class="str"&gt;'smith'&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt; &lt;br /&gt;        First_Name = &lt;span class="str"&gt;'Jake'&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;font size="2"&gt;It should be pretty obvious that the ix_Customer_Name index would work well to satisfy this query. A quick look at the execution plan confirms our expectations.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes0-2008-02-13_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="111" alt="CompositeIndexes0-2008-02-13" width="240" border="0" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes0-2008-02-13_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;Finding a last name&lt;/h3&gt;
&lt;p&gt;Now, let's broaden our search a bit to retrieve all customers whose last name is Smith. The following query may be executed for this.&lt;/p&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;&lt;br /&gt;        *&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;        Customers&lt;br /&gt;&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;&lt;br /&gt;        Last_Name = &lt;span class="str"&gt;'smith'&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Looking at the query execution plan, we can see that SQL Server did indeed use the ix_Customer_Name composite index; it performed an index seek to find the rows that satisfied the query, then it used a Key Lookup to retrieve the non-indexed column information. You'll notice that this time, however, more work was expended in the Key Lookup than in the Index Seek. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes1-2008-02-13_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="111" alt="CompositeIndexes1-2008-02-13" width="240" border="0" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes1-2008-02-13_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Returning to our telephone book analogy, we can see why this index was deemed efficient by the Query Optimizer. To find all of the Smiths in the telephone book, we'd navigate to the page that contains the first Smith and keep moving forward until we found something other than Smith. &lt;/p&gt;
&lt;h3&gt;Finding a first name&lt;/h3&gt;
&lt;p&gt;Now, let's see what happens if we need to find all people who have a first name of Jake. Let's execute the following query.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;&lt;br /&gt;        *&lt;br /&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;        Customers&lt;br /&gt;&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;&lt;br /&gt;        First_Name = &lt;span class="str"&gt;'Jake'&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;This yields the following query execution plan.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes2-2008-02-13_2.jpg"&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="137" alt="CompositeIndexes2-2008-02-13" width="240" border="0" src="http://weblogs.sqlteam.com/images/weblogs_sqlteam_com/joew/WindowsLiveWriter/Doestheorderofcolumnsinanindexmatter_298B/CompositeIndexes2-2008-02-13_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Notice that this time, SQL Server used a Clustered Index Scan to resolve the query. This is tantamount to a complete table scan. It did not use our ix_Customer_Name index. &lt;/p&gt;
&lt;p&gt;Once again, returning to the telephone book example, we can see why. Think about find all of the Jakes in the telephone book. You'd have to start on the first page of the book and look through every entry. Why? Because it's not organized by first name; it's organized by last name, first name. &lt;/p&gt;
&lt;p&gt;Does this mean that composite indexes are worthless? No. They have great value to SQL Server. In our first example we were able to use the ix_Customer_Name index to navigate directly to Smith, Jake. We just need to give considerable forethought to the kinds of queries our applications will be submitting to our server and create the appropriate indexes to handle those queries. &lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f13%2f60510.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f13%2f60510.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60510.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/02/13/60510.aspx</guid>
            <pubDate>Wed, 13 Feb 2008 16:43:08 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60510.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/02/13/60510.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60510.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using CROSS JOIN to generate test data</title>
            <link>http://weblogs.sqlteam.com/joew/archive/2008/02/06/60490.aspx</link>
            <description>&lt;p&gt;To prepare for an upcoming technical presentation, I need to create some test data to use in a demo. I'm planning to show how different T-SQL programming techniques directly affect SQL Server's efficiency in resolving the query. So, 10 - 20 million rows of data will likely suffice for this demo. &lt;/p&gt;
&lt;p&gt;The question is: how to create all of that data? Obviously, a simple INSERT...VALUES statement is good for creating up to a few dozen rows of data, but 10 - 20 million rows of data is out of the question for such a simple technique. &lt;/p&gt;
&lt;p&gt;Fortunately, SQL Server has a oft forgotten JOIN type that helps for occasions such as this. We're all pretty familiar with INNER JOIN, LEFT JOIN, and RIGHT JOIN. But are you aware of the CROSS JOIN? A CROSS JOIN takes each row from the first table and combines it with every row from the second table, resulting in a Cartesian product of the two tables. For example, if my first table has 3 rows of data - Mary, Mark, Luke - and my second table has 2 rows of data - Jones, Smith - the Cartesian product will result in 6 rows of data. &lt;/p&gt;
&lt;table width="200" cellspacing="0" cellpadding="2" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;&lt;strong&gt;First_Name&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;&lt;strong&gt;Last_Name&lt;/strong&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Mary&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;Jones&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Mary&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;Smith&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Mark&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;Jones&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Mark&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;Smith&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Luke&lt;/td&gt;
            &lt;td width="99" valign="top"&gt;Jones&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td width="99" valign="top"&gt;Luke&lt;/td&gt;
            &lt;td width="100" valign="top"&gt;Smith&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;So I have the "how". Now I need the "what".&lt;/p&gt;
&lt;p&gt;A quick search on Google led me to the United States Census site where the most popular male, female, and family names are readily available. I downloaded each of those files.There were a total of 5,494 given names and 88,799 family names. I pruned the list of family names down to 2,500 since the original list would have produced a whopping 487,861,706 customers (88,799 * 5,494); far more than I required.&lt;/p&gt;
&lt;p&gt;After importing the two lists into two tables, appropriately called Last_Names and First_Names, I used the following script to create my test data.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="csharpcode"&gt;--clean up the imported &lt;span class="kwrd"&gt;names&lt;/span&gt; &lt;br /&gt;&lt;span class="kwrd"&gt;UPDATE&lt;/span&gt;         &lt;br /&gt;	First_Names &lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt;     &lt;br /&gt;        Given_Name = RTRIM(Given_Name)&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;UPDATE&lt;br /&gt;&lt;/span&gt;	Last_Names &lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt;     &lt;br /&gt;        Family_Name = RTRIM(Family_Name)&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="csharpcode"&gt;--&lt;span class="kwrd"&gt;create&lt;/span&gt; a very simple customers &lt;span class="kwrd"&gt;table&lt;/span&gt; &lt;br /&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; Customers&lt;br /&gt;        (&lt;br /&gt;         Customer_ID &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1,1)&lt;br /&gt;        ,Last_Name &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(20) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;br /&gt;&lt;/span&gt;	,First_Name &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(20) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;	,Email_Address &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(50) &lt;span class="kwrd"&gt;NULL&lt;br /&gt;	&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="csharpcode"&gt; &lt;/pre&gt;
&lt;pre class="csharpcode"&gt;--&lt;span class="kwrd"&gt;create&lt;/span&gt; the test &lt;span class="kwrd"&gt;data&lt;/span&gt; &lt;br /&gt;INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt;&lt;br /&gt;	 Customers &lt;br /&gt;		(&lt;br /&gt;	 	 Last_Name&lt;br /&gt;		,First_Name&lt;br /&gt;		,Email_Address&lt;br /&gt;		 )&lt;br /&gt;&lt;span class="kwrd"&gt;SELECT&lt;br /&gt;	&lt;/span&gt; f.Given_Name&lt;br /&gt;	 ,l.Family_Name&lt;br /&gt;	 ,f.Given_Name + &lt;span class="str"&gt;'.'&lt;/span&gt; + l.Family_Name + &lt;span class="str"&gt;'@hotmail.com'&lt;br /&gt;&lt;/span&gt;&lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;	 First_Names &lt;span class="kwrd"&gt;AS&lt;/span&gt; f &lt;span class="kwrd"&gt;CROSS&lt;/span&gt; &lt;span class="kwrd"&gt;JOIN&lt;br /&gt;	&lt;/span&gt; Last_Names &lt;span class="kwrd"&gt;AS&lt;/span&gt; l&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;My new Customers table now has 13,735,000 rows in it. (A real business should be so fortunate!) I think that'll do nicely for my presentation. If not, I start over and create a 50 millions rows. &lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;Joe&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f06%2f60490.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.sqlteam.com%2fjoew%2farchive%2f2008%2f02%2f06%2f60490.aspx" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.sqlteam.com/joew/aggbug/60490.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Joe Webb</dc:creator>
            <guid>http://weblogs.sqlteam.com/joew/archive/2008/02/06/60490.aspx</guid>
            <pubDate>Wed, 06 Feb 2008 16:14:15 GMT</pubDate>
            <wfw:comment>http://weblogs.sqlteam.com/joew/comments/60490.aspx</wfw:comment>
            <comments>http://weblogs.sqlteam.com/joew/archive/2008/02/06/60490.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/joew/comments/commentRss/60490.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>