<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>SQL RNNR</title>
	
	<link>http://jasonbrimhall.info</link>
	<description>1 DBA's Professional Blog</description>
	<lastBuildDate>Mon, 30 Jan 2012 13:00:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SqlRnnr" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="sqlrnnr" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>System Base Tables</title>
		<link>http://jasonbrimhall.info/2012/01/30/system-base-tables/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=system-base-tables</link>
		<comments>http://jasonbrimhall.info/2012/01/30/system-base-tables/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 13:00:43 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[MCM]]></category>
		<category><![CDATA[SQL Internals]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1594</guid>
		<description><![CDATA[On January 19th, I published a post about the Dedicated Administrator Connection.  I spoke very briefly of the system base tables in that article.  Today, I want to dive into these tables a little bit more. First, let&#8217;s get the Microsoft definition for these tables.  &#8221;System base tables are the [...]]]></description>
			<content:encoded><![CDATA[<p>On January 19th, I published a post about the <a href="http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/">Dedicated Administrator Connection</a>.  I spoke very briefly of the system base tables in that article.  Today, I want to dive into these tables a little bit more.</p>
<p>First, let&#8217;s get the <a href="http://msdn.microsoft.com/en-us/library/ms179503.aspx">Microsoft definition</a> for these tables.  &#8221;System base tables are the underlying tables that actually store the metadata for a specific database.&#8221;</p>
<p>Have you ever queried sys.objects from the master database and wondered about some of the results?  You can see all of the System base tables when querying the sys.objects view.  These tables are denoted in sys.objects by type of &#8216;S&#8217; and a type_desc of &#8216;SYSTEM_TABLE&#8217;.</p>
<p>Here is a simple query to take a quick peek at these tables.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">SELECT</span> <span class="sy0">*</span> <span class="kw1">FROM</span> sys.<span class="me1">objects</span>
	<span class="kw1">WHERE</span> Type <span class="sy0">=</span> <span class="st0">'S'</span>
	<span class="kw1">ORDER</span> <span class="kw1">BY</span> NAME</pre></div></div>
<p>There is no need for a Dedicated Administrator connection in order for this query to work.  You can view these results with a non-DAC connection to the instance so long as you have adequate permissions to query sys.objects.  That said, not all objects returned by that query are System Base Tables.  Furthermore, it appears that the list from <a href="http://msdn.microsoft.com/en-us/library/ms179503.aspx">MSDN</a> is not comprehensive.  One such example is the reference to sys.sysserrefs that does not appear to exist in SQL 2008 R2 and the missing System Base table called sys.sysbrickfiles (which is used by sysaltfiles as shown in this execution plan).</p>
<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/brickfiles.png"><img class="alignnone size-full wp-image-1599" title="brickfiles" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/brickfiles.png" alt="" width="600" height="116" /></a></p>
<p>If I try to query the sysbrickfiles table (as an example) without connecting via DAC, I will get an error message like this:</p>
<pre>Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.sysbrickfiles'.</pre>
<p>This is normal behavior.  You cannot query the system base tables without first connecting via DAC.  Having said that, the obligatory warning is required.  As explained on MSDN, these tables are intended for use by Microsoft.  Proceed at your own risk and please make sure you have backups.</p>
<p>In addition to these System Base tables, you will find tables not mentioned in the article nor in the master database.  These System Base tables are found within the Resource database.  The resource database does contain most of the tables mentioned in that article, but there are some differences.  I will leave that discovery exercise to the reader.</p>
<p>There is plenty about SQL Server that many of us take for granted.  Under the hood, there is much more to learn.  Taking a peek at the System Base tables is one of those areas that will help you to learn more about SQL Server.  My question is this: How far are you willing to explore to learn more about SQL Server?</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/" rel="bookmark" class="crp_title">Dedicated Administrator Connection</a></li><li><a href="http://jasonbrimhall.info/2011/03/22/sql-resource/" rel="bookmark" class="crp_title">SQL Resource</a></li><li><a href="http://jasonbrimhall.info/2011/02/25/finding-compressed-tables/" rel="bookmark" class="crp_title">Finding Compressed Tables</a></li><li><a href="http://jasonbrimhall.info/2010/01/12/primary-key-discovery-ii/" rel="bookmark" class="crp_title">Primary Key Discovery II</a></li><li><a href="http://jasonbrimhall.info/2011/09/19/column-level-permissions/" rel="bookmark" class="crp_title">Column Level Permissions</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1594" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=wQzatBafrpc:PGTok2YkXiw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=wQzatBafrpc:PGTok2YkXiw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=wQzatBafrpc:PGTok2YkXiw:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=wQzatBafrpc:PGTok2YkXiw:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/wQzatBafrpc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/30/system-base-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slammer, Alive…Barely</title>
		<link>http://jasonbrimhall.info/2012/01/24/slammer-alive-barely/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=slammer-alive-barely</link>
		<comments>http://jasonbrimhall.info/2012/01/24/slammer-alive-barely/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 18:15:37 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1596</guid>
		<description><![CDATA[Slammer By now you must have heard of the SQL Slammer worm.  It was quite an infectious little nuisance.  The harm it caused came largely due to unpatched, unprotected SQL Servers. We are now 9 years out from the initial discovery of this worm.  The worm has made its way [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="border-style: initial; border-color: initial; line-height: 15px;" title="Worms with Teeth" src="http://scienceblogs.com/tetrapodzoology/Langham_slow_worm_Shoreham_by_Sea.JPG" alt="" width="343" height="255" /></p>
<h3>Slammer</h3>
<p>By now you must have heard of the SQL Slammer worm.  It was quite an infectious little nuisance.  The harm it caused came largely due to unpatched, unprotected SQL Servers.</p>
<p>We are now 9 years out from the initial discovery of this worm.  The worm has made its way onto the endangered species list &#8211; but it is not yet extinct.  I don&#8217;t know if I should be surprised by that.</p>
<p>My initial reaction is &#8220;No way that worm is still causing problems.  Everybody knows about it.&#8221;  But yet, I just caught several infection attempts from remote hosts that were affected by Slammer.  When I take a step back, I recall that many people out there are still running on unpatched servers.  I know of many places that are running SQL 2000.  I know of a large pool of servers across different versions and editions that are not patched.  I even know of a few places that are still running SQL 6.5.</p>
<p>When I take all of that into account, finding that Slammer is still active does not surprise me &#8211; but it should.</p>
<p>So for fun, here is what I was able to trap from the recent attempts at my machine with SQL Slammer.</p>
<blockquote>
<pre>Time:		 1/23/2012 3:59:03 PM
Event:		 Intrusion
IP Address/User: 202.56.192.195
Message:	 Attack type: MSSQL Resolution Service Buffer Overflow (Slammer)</pre>
</blockquote>
<p>When I trace that IP back to its source, I get a host name of the machine.  If I search on the Host Name of the IP Address, I find this <a href="https://ipdb.at/ip/202.56.192.195">page</a>.  If I were a hacker, I now have a lot of valuable information.  I can also assume that this particular host has many virii.</p>
<p>This entire little foray has made me wonder how many people out there are concerned about security.  Do you know what the patch level is of your server?  Is your AV software up to date?  Are you running any form of HIPS?  If you are in IT and your focus is Data, you may want to check those things.  After all, our focus is to protect the data.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2011/12/30/january-2012-las-vegas-sql-ug/" rel="bookmark" class="crp_title">January 2012 Las Vegas SQL UG</a></li><li><a href="http://jasonbrimhall.info/2011/09/14/what-happens-in-vegas/" rel="bookmark" class="crp_title">What Happens in Vegas&#8230;</a></li><li><a href="http://jasonbrimhall.info/2011/12/06/december-event-reminder/" rel="bookmark" class="crp_title">December Event Reminder</a></li><li><a href="http://jasonbrimhall.info/2010/02/15/in-vs-inner-join/" rel="bookmark" class="crp_title">In Vs. Inner Join</a></li><li><a href="http://jasonbrimhall.info/2011/06/14/t-sql-tuesday-19-%e2%80%93-disasters-recovery/" rel="bookmark" class="crp_title">T-SQL Tuesday #19 – Disasters &#038; Recovery</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1596" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=QO__W6dSl_o:26OBCbSWA7Y:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=QO__W6dSl_o:26OBCbSWA7Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=QO__W6dSl_o:26OBCbSWA7Y:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=QO__W6dSl_o:26OBCbSWA7Y:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/QO__W6dSl_o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/24/slammer-alive-barely/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>S3OLV February 2012</title>
		<link>http://jasonbrimhall.info/2012/01/23/s3olv-february-2012/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=s3olv-february-2012</link>
		<comments>http://jasonbrimhall.info/2012/01/23/s3olv-february-2012/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 12:00:41 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[S3OLV]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1591</guid>
		<description><![CDATA[Do you recognize this person? &#160; If you are from the Colorado Springs area, you probably do.  This is: &#160; &#160; &#160; Troy Ketsdever (twitter) Troy will be presenting to the Las Vegas SQL User Group on February 9, 2012 @ 6:30 Pacific.  Here is his bio: Troy Ketsdever is [...]]]></description>
			<content:encoded><![CDATA[<p>Do you recognize this person?</p>
<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/small_bio_photo.jpg"><img class="size-full wp-image-1592 alignnone" title="small_bio_photo" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/small_bio_photo.jpg" alt="" width="300" height="300" /></a></p>
<p>&nbsp;</p>
<p>If you are from the Colorado Springs area, you probably do.  This is:</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Troy Ketsdever (<a href="https://twitter.com/#!/42and5">twitter</a>)</h3>
<p>Troy will be presenting to the Las Vegas SQL User Group on February 9, 2012 @ 6:30 Pacific.  Here is his bio:</p>
<p>Troy Ketsdever is a data architect with over 15 years of commercial software development experience, and has maintained a love/hate relationship with SQL Server since version 4.2. In addition to his &#8220;day job&#8221;, Troy enjoys writing articles and presenting at user groups on a variety of database design and implementation topics.</p>
<p>His main objective and vision is “making the right information available to the right people at the right time”.</p>
<p>The topic that Troy has chosen for this meeting is titled: <strong>Zero to &#8220;MERGE&#8221; in 60 minutes</strong>.  And here is the abstract for that presentation.</p>
<p>Description: SQL Server 2008 saw the introduction of the new MERGE DML statement. In this session, we&#8217;ll take a look at the basic syntax and capabilities of the command. Once we have reviewed some simple examples, we&#8217;ll dive into some of the more advanced uses (abuses?) of the command, reinforcing our understanding by looking at more complex examples.</p>
<p>Bring your questions.  Bring your <strong>ugly code</strong>.  If you are remote, bring your own PIZZA.  Yes, this meeting will be both virtual and in person.</p>
<h3>Virtual Meeting Info</h3>
<p><strong>Attendee URL</strong>: https://www.livemeeting.com/cc/UserGroups/join?id=H3ZGRQ&amp;role=attend</p>
<p><strong>Meeting ID</strong>:  H3ZGRQ</p>
<h3>Physical Meeting Info</h3>
<p>M Staff Solutions &amp; Training / 2620 Regatta Drive Suite 102 Las Vegas, NV 89128</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2011/11/30/december-2011-lv-ug-meeting/" rel="bookmark" class="crp_title">December 2011 LV UG Meeting</a></li><li><a href="http://jasonbrimhall.info/2012/01/20/s3olv-jan-2012-meeting-recap/" rel="bookmark" class="crp_title">S3OLV &#8211; Jan 2012 Meeting Recap</a></li><li><a href="http://jasonbrimhall.info/2011/11/07/sssolv-november-2011-meeting/" rel="bookmark" class="crp_title">SSSOLV November 2011 Meeting</a></li><li><a href="http://jasonbrimhall.info/2011/12/30/january-2012-las-vegas-sql-ug/" rel="bookmark" class="crp_title">January 2012 Las Vegas SQL UG</a></li><li><a href="http://jasonbrimhall.info/2011/02/09/feb-2011-s3olv-meeting/" rel="bookmark" class="crp_title">Feb 2011 S3OLV Meeting</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1591" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=YCp0QPvDndU:t3S3SyHDnWw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=YCp0QPvDndU:t3S3SyHDnWw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=YCp0QPvDndU:t3S3SyHDnWw:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=YCp0QPvDndU:t3S3SyHDnWw:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/YCp0QPvDndU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/23/s3olv-february-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>S3OLV – Jan 2012 Meeting Recap</title>
		<link>http://jasonbrimhall.info/2012/01/20/s3olv-jan-2012-meeting-recap/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=s3olv-jan-2012-meeting-recap</link>
		<comments>http://jasonbrimhall.info/2012/01/20/s3olv-jan-2012-meeting-recap/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 22:04:11 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[S3OLV]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1587</guid>
		<description><![CDATA[Last week (Jan 12, 2012), we held the user group meeting for the SQL Server Society of Las Vegas (a.k.a S3OLV or SSSOLV). Presenting at that meeting was Josh Lewis (Twitter).  Josh presented on a pretty tough topic in my opinion.  He chose to present to us the topic of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/las_vegas.jpg"><img class="size-full wp-image-1588 alignright" title="las_vegas" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/las_vegas.jpg" alt="" width="360" height="248" /></a>Last week (Jan 12, 2012), we held the user group meeting for the SQL Server Society of Las Vegas (a.k.a S3OLV or SSSOLV).</p>
<p>Presenting at that meeting was Josh Lewis (<a href="https://twitter.com/#!/deusexdatum">Twitter</a>).  Josh presented on a pretty tough topic in my opinion.  He chose to present to us the topic of XML for the DBA.  You can read his abstract <a href="http://jasonbrimhall.info/2011/12/30/january-2012-las-vegas-sql-ug/">here</a>.</p>
<p>We got the meeting rolling a little bit late.  Traffic must have been a bear down in LV.  Nonetheless, it got rolling and was a good meeting.</p>
<p>During this meeting we had our second installment of &#8220;Crap Code.&#8221;  Unintentionally, the crap code was a perfect segue into the presentation.  The crap code demonstrated extracting elements from XML related to the blocked process report.</p>
<p>Josh did a great job on the topic.  We recorded the meeting and you can view that <a href="https://www323.livemeeting.com/cc/UserGroups/view?id=GW2GD2">here</a>.  Check it out.  Get a little free learning on a difficult topic (for some us like myself).</p>
<p>Stay tuned, the February announcement is coming soon.</p>
<p>&nbsp;</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2012/01/23/s3olv-february-2012/" rel="bookmark" class="crp_title">S3OLV February 2012</a></li><li><a href="http://jasonbrimhall.info/2011/01/20/january-2011-meeting-recap/" rel="bookmark" class="crp_title">January 2011 Meeting Recap</a></li><li><a href="http://jasonbrimhall.info/2011/10/11/october-2011-lv-ug-meeting/" rel="bookmark" class="crp_title">October 2011 LV UG Meeting</a></li><li><a href="http://jasonbrimhall.info/2011/12/06/december-event-reminder/" rel="bookmark" class="crp_title">December Event Reminder</a></li><li><a href="http://jasonbrimhall.info/2011/10/18/october-2011-lv-ug-meeting-update/" rel="bookmark" class="crp_title">October 2011 LV UG Meeting Update</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1587" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=FPHr9jH3eFk:WW0zEK99w4I:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=FPHr9jH3eFk:WW0zEK99w4I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=FPHr9jH3eFk:WW0zEK99w4I:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=FPHr9jH3eFk:WW0zEK99w4I:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/FPHr9jH3eFk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/20/s3olv-jan-2012-meeting-recap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dedicated Administrator Connection</title>
		<link>http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=dedicated-administrator-connection</link>
		<comments>http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 13:00:07 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[DAC]]></category>
		<category><![CDATA[MCM]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1582</guid>
		<description><![CDATA[Recently you may have read my article about some hidden functions in SQL Server.  In that article you learned that those functions were in some DMOs and that you could get at them through the resource database. Today I found myself learning more about the resource database.  Due to what [...]]]></description>
			<content:encoded><![CDATA[<p>Recently you may have read my <a href="http://jasonbrimhall.info/2012/01/17/a-trio-of-functions/">article </a>about some hidden functions in SQL Server.  In that article you learned that those functions were in some DMOs and that you could get at them through the resource database.</p>
<p>Today I found myself learning more about the resource database.  Due to what I had learned in my prior foray into the resource database, I was curious if certain other functions might call some hidden functions in that database.</p>
<p>Sadly &#8211; they did not.  But in my travels I did happen across something else that is in that database.  Those items are called <a href="http://msdn.microsoft.com/en-us/library/ms179503.aspx">system base tables</a>.  Unlike the trio of functions from the last article &#8211; you can get to these but it is <strong>STRONGLY</strong> advised to not do it.</p>
<p>Naturally, I want to check these tables out &#8211; especially since the <a href="http://msdn.microsoft.com/en-us/library/ms179503.aspx">MSDN </a>article does say how to get to them.  I will write about some adventures into looking at these tables in the future.  I already found one interesting thing that seemed odd &#8211; but first I will need to login using the DAC and start testing to confirm a hypothesis.</p>
<p>For now, I want to cover how to create a Dedicated Administrator Connection.  This should be something that DBAs know how to do.  It isn&#8217;t difficult, and I will only cover one method and leave the other method to the Microsoft documentation.</p>
<p>You can create a DAC through either SSMS or through SQLCMD.  You can create one remotely, but you will need to enable that option since it is disabled by default.  You can find the method for creating this connection via SQLCMD <a href="http://msdn.microsoft.com/en-us/library/ms189595.aspx">here</a>.</p>
<p>To create a connection through SSMS, it is rather easy as well.  You simply add (case insensitive) &#8220;admin:&#8221; to the beginning of your server as shown in this image.</p>
<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/configure.png"><img class="size-full wp-image-1583 alignnone" title="configure" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/configure.png" alt="" width="408" height="513" /></a></p>
<p>In order for this to work, you will need to have the browser service running.  If it is not running, you will get an error message.  This error message is informative if you read it.  It will provide a clue to look at the browser service.</p>
<p>Once you have successfully created this connection, you can now use it when necessary to perform administrative tasks or for some learning opportunities.  If you open a query using this connection you will see something like this next image in your query tab.</p>
<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/confirm_connect.png"><img class="alignleft size-full wp-image-1584" title="confirm_connect" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/confirm_connect.png" alt="" width="245" height="77" /></a>You can see in the tab of this query tab that there is the label &#8220;ADMIN:&#8221;.  This is your DAC connection.  You are limited to one of these at a time &#8211; period.</p>
<p>If you try to create a second connection, you will get a nasty message.  The message is not entirely informative &#8211; just understand that you are getting it because you already have a DAC open.</p>
<p><a href="http://jasonbrimhall.info/wp-content/uploads/2012/01/dac_error.png"><img class="alignnone size-full wp-image-1585" title="dac_error" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/dac_error.png" alt="" width="553" height="121" /></a></p>
<p>It is a good idea to become familiar with how to connect via the DAC.  I have a connection saved for quick access.  Luckily I have a development server which I can test and use for learning opportunities.  As the warning <a href="http://msdn.microsoft.com/en-us/library/ms179503.aspx">MSDN </a>states: &#8220;Access to system base tables by using DAC is designed only for Microsoft personnel, and it is not a supported customer scenario.&#8221;  If you venture into the system base tables via the DAC &#8211; Microsoft will not support it if you break it.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2012/01/30/system-base-tables/" rel="bookmark" class="crp_title">System Base Tables</a></li><li><a href="http://jasonbrimhall.info/2010/12/28/ssis-multiple-file-export/" rel="bookmark" class="crp_title">SSIS Multiple File Export</a></li><li><a href="http://jasonbrimhall.info/2011/03/22/sql-resource/" rel="bookmark" class="crp_title">SQL Resource</a></li><li><a href="http://jasonbrimhall.info/2012/01/17/a-trio-of-functions/" rel="bookmark" class="crp_title">A Trio of Functions</a></li><li><a href="http://jasonbrimhall.info/2010/01/05/primary-key-discovery/" rel="bookmark" class="crp_title">Primary Key Discovery</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1582" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=70jpBKwowC0:ehBFRHmILJg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=70jpBKwowC0:ehBFRHmILJg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=70jpBKwowC0:ehBFRHmILJg:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=70jpBKwowC0:ehBFRHmILJg:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/70jpBKwowC0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blackout</title>
		<link>http://jasonbrimhall.info/2012/01/18/blackout/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=blackout</link>
		<comments>http://jasonbrimhall.info/2012/01/18/blackout/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 17:58:06 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[BLACKOUT]]></category>
		<category><![CDATA[MORONIC LEGISLATION]]></category>
		<category><![CDATA[PIPA]]></category>
		<category><![CDATA[SOPA]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1577</guid>
		<description><![CDATA[What more can I say.  I disagree with the kind of legislation that is being presented via SOPA and PIPA. In support of the community, my site will be dark 18 Jan 2012 between 10:30 and 21:30 GMT-8. Normal services will return after that. &#160; You can see support of [...]]]></description>
			<content:encoded><![CDATA[<p>What more can I say.  I disagree with the kind of legislation that is being presented via SOPA and PIPA.</p>
<p>In support of the community, my site will be dark 18 Jan 2012 between 10:30 and 21:30 GMT-8.</p>
<p>Normal services will return after that.</p>
<p>&nbsp;</p>
<p>You can see support of this from some more reputable sites as well.</p>
<p><a href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a></p>
<p>&nbsp;</p>
<p><a href="http://www.sqlservercentral.com/blogs/steve_jones/2012/01/18/blackout/">Steve Jones</a> @ SqlServerCentral</p>
<p><a href="http://www.sqlservercentral.com/blogs/scarydba/2012/01/18/stop-pipa-sopa/">Grant Fritchey</a></p>
<p><a href="http://sqlinthewild.co.za/">Gail Shaw</a></p>
<p>&nbsp;</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2010/05/20/plagiarized/" rel="bookmark" class="crp_title">Plagiarized or Copied</a></li><li><a href="http://jasonbrimhall.info/2012/01/20/s3olv-jan-2012-meeting-recap/" rel="bookmark" class="crp_title">S3OLV &#8211; Jan 2012 Meeting Recap</a></li><li><a href="http://jasonbrimhall.info/2012/01/23/s3olv-february-2012/" rel="bookmark" class="crp_title">S3OLV February 2012</a></li><li><a href="http://jasonbrimhall.info/2012/01/09/meme-monday-january-2012/" rel="bookmark" class="crp_title">Meme Monday January 2012</a></li><li><a href="http://jasonbrimhall.info/2011/09/14/what-happens-in-vegas/" rel="bookmark" class="crp_title">What Happens in Vegas&#8230;</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1577" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=gT1y9eDjT9A:eB2RxLB9THo:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=gT1y9eDjT9A:eB2RxLB9THo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=gT1y9eDjT9A:eB2RxLB9THo:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=gT1y9eDjT9A:eB2RxLB9THo:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/gT1y9eDjT9A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/18/blackout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Trio of Functions</title>
		<link>http://jasonbrimhall.info/2012/01/17/a-trio-of-functions/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-trio-of-functions</link>
		<comments>http://jasonbrimhall.info/2012/01/17/a-trio-of-functions/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 13:00:04 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1573</guid>
		<description><![CDATA[I found myself perusing an execution plan the other day.  I know, big surprise there.  This execution plan showed me some interesting things I had never really paid much attention to in the past.  When I started paying attention to these things, I found myself jumping down a rabbit hole. [...]]]></description>
			<content:encoded><![CDATA[<p>I found myself perusing an execution plan the other day.  I know, big surprise there.  This execution plan showed me some interesting things I had never really paid much attention to in the past.  When I started paying attention to these things, I found myself jumping down a rabbit hole.</p>
<p>It all started with a bit of curiosity to see if I could make an &#8220;admin&#8221; script perform a bit better.  The execution plans started showing some table valued functions that I knew I hadn&#8217;t included in the query.  Subsequently, I found myself wondering &#8211; what is that?</p>
<p>The items that made me curious were all table valued functions.  There were three of them (different) in this particular plan.  I started looking hither and thither to find these functions.  It didn&#8217;t take long to figure out that I could find them in the mssqlsystemresource database.  So I proceeded to making a copy of the database and attaching a copy of it for further learning opportunities.</p>
<p>The three functions are:</p>
<p>SYSSESSIONS</p>
<p>FNGETSQL</p>
<p>SYSCONNECTIONS</p>
<p>Knowing the query and based on these names, I began looking in the appropriate DMOs to see what I could find.  Here are the scripts for each of those DMO&#8217;s.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">USE</span> <span class="br0">&#91;</span>mssqlsystemresource_test<span class="br0">&#93;</span>
GO
&nbsp;
<span class="coMULTI">/****** Object:  View [sys].[dm_exec_connections]    Script Date: 01/16/2012 22:39:32 ******/</span>
<span class="kw1">SET</span> ANSI_<span class="sy0">NULL</span>S <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">SET</span> QUOTED_IDENTIFIER <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">CREATE</span> <span class="kw1">VIEW</span> <span class="br0">&#91;</span>sys<span class="br0">&#93;</span>.<span class="br0">&#91;</span>dm_exec_connections<span class="br0">&#93;</span> <span class="kw1">AS</span>
	<span class="kw1">SELECT</span> <span class="sy0">*</span>
	<span class="kw1">FROM</span> <span class="kw1">OPENROWSET</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SYSCONNECTIONS<span class="br0">&#41;</span>
&nbsp;
GO
&nbsp;
<span class="coMULTI">/****** Object:  View [sys].[dm_exec_sessions]    Script Date: 01/16/2012 22:39:37 ******/</span>
<span class="kw1">SET</span> ANSI_<span class="sy0">NULL</span>S <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">SET</span> QUOTED_IDENTIFIER <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">CREATE</span> <span class="kw1">VIEW</span> <span class="br0">&#91;</span>sys<span class="br0">&#93;</span>.<span class="br0">&#91;</span>dm_exec_sessions<span class="br0">&#93;</span> <span class="kw1">AS</span>
	<span class="kw1">SELECT</span> <span class="sy0">*</span>
	<span class="kw1">FROM</span> <span class="kw1">OPENROWSET</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SYSSESSIONS<span class="br0">&#41;</span>
&nbsp;
GO
&nbsp;
<span class="coMULTI">/****** Object:  UserDefinedFunction [sys].[dm_exec_sql_text]    Script Date: 01/16/2012 22:39:55 ******/</span>
<span class="kw1">SET</span> ANSI_<span class="sy0">NULL</span>S <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">SET</span> QUOTED_IDENTIFIER <span class="kw1">ON</span>
GO
&nbsp;
<span class="kw1">CREATE</span> <span class="kw1">FUNCTION</span> <span class="br0">&#91;</span>sys<span class="br0">&#93;</span>.<span class="br0">&#91;</span>dm_exec_sql_text<span class="br0">&#93;</span><span class="br0">&#40;</span>@handle <span class="kw1">VARBINARY</span><span class="br0">&#40;</span>64<span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="kw1">RETURNS</span> <span class="kw1">TABLE</span>
<span class="kw1">AS</span>
	<span class="kw1">RETURN</span> <span class="kw1">SELECT</span> <span class="sy0">*</span> <span class="kw1">FROM</span> <span class="kw1">OPENROWSET</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> FNGETSQL, @handle<span class="br0">&#41;</span>
&nbsp;
GO</pre></div></div>
<p>Cool.  I can now see the internals of each of the DMOs &#8211; sort of.  You see, there is an <a href="http://msdn.microsoft.com/en-us/library/ms190312.aspx">OPENROWSET </a>call in each of these objects.  Each call uses an undocumented feature called TABLE.  This is an internal command used by the engine and you won&#8217;t find much on it (mostly people asking what it is and Microsoft saying they won&#8217;t tell).</p>
<p>Here is the fun part.  If you try to run that code outside of querying the DMO, you will receive error messages.  If you try to create a new view utilizing the Openrowset, it will fail.  It is reserved for internal usage.  With that said, just continue to use the DMO and you will be fine.  Personally, I was curious to find out how it worked so I tried a bit to find it.</p>
<p>So there you have it.  If you are curious what is the internal makings of these DMOs, you can script them from the resource database.  Alternatively, you could also run sp_helptext.  I like to check these things from the resource database.  It feels more like an adventure.  Have fun with it and see what you will learn.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2012/01/19/dedicated-administrator-connection/" rel="bookmark" class="crp_title">Dedicated Administrator Connection</a></li><li><a href="http://jasonbrimhall.info/2012/01/30/system-base-tables/" rel="bookmark" class="crp_title">System Base Tables</a></li><li><a href="http://jasonbrimhall.info/2011/02/25/finding-compressed-tables/" rel="bookmark" class="crp_title">Finding Compressed Tables</a></li><li><a href="http://jasonbrimhall.info/2011/03/22/sql-resource/" rel="bookmark" class="crp_title">SQL Resource</a></li><li><a href="http://jasonbrimhall.info/2011/11/08/t-sql-tuesday-024-prox-%e2%80%98n%e2%80%99-funx/" rel="bookmark" class="crp_title">T-SQL Tuesday #024: Prox ‘n’ Funx</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1573" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=ZdfEf875nNM:xDN8UNCMbvQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=ZdfEf875nNM:xDN8UNCMbvQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=ZdfEf875nNM:xDN8UNCMbvQ:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=ZdfEf875nNM:xDN8UNCMbvQ:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/ZdfEf875nNM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/17/a-trio-of-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Meme15 Twitter</title>
		<link>http://jasonbrimhall.info/2012/01/16/meme15-twitter/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=meme15-twitter</link>
		<comments>http://jasonbrimhall.info/2012/01/16/meme15-twitter/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 14:00:21 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[Meme15]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[MEME15]]></category>
		<category><![CDATA[SQLFamily]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1558</guid>
		<description><![CDATA[Twitter and Your Career With the new blog party on the block, we have Jason Strate (blog &#124; twitter) asking us this month these two questions: Why should average Jane or Joe professional consider using twitter? What benefit have you seen in your career because of twitter? But first, a [...]]]></description>
			<content:encoded><![CDATA[<h1></h1>
<h1>Twitter and Your Career</h1>
<h1><a href="http://www.jasonstrate.com/2012/01/january-meme15-assignment/"><img class="size-full wp-image-1571 alignright" title="meme15new" src="http://jasonbrimhall.info/wp-content/uploads/2012/01/meme15new.png" alt="" width="150" height="150" /></a></h1>
<p>With the new blog party on the block, we have Jason Strate (<a href="http://www.jasonstrate.com/">blog </a>| <a href="http://twitter.com/stratesql">twitter</a>) asking us this month these two questions:</p>
<ol>
<li>Why should average Jane or Joe professional consider using twitter?</li>
<li>What benefit have you seen in your career because of twitter?</li>
</ol>
<p>But first, a little background.  This blog party is an experiment in exploring the use of <a href="http://www.jasonstrate.com/2012/01/january-meme15-assignment/">social networking and other medium (such as blogs) to enhance your career and professional development</a>.  You can read about that in the link from this months invitation.</p>
<p>For myself, it will be very useful to participate as I explore these kinds of questions in answer for myself.  So, let&#8217;s get to the two questions at hand for this months topic.</p>
<h3>Why should average Jane or Joe professional consider using twitter?</h3>
<p>This question is one I had to explore back when I first started using twitter.  I even wrote a blog or two about it.</p>
<p>I first was having a difficult time justifying it for myself.  I wrote about that <a href="http://jasonbrimhall.info/2010/01/18/tweet-tweet-tweetilly-deet/">here</a>.  But a little while later, I started to see that there was some worth to it and decided to take the <a href="http://jasonbrimhall.info/2010/01/25/tweeting-i-took-the-dive/">plunge</a>.</p>
<p>There are many benefits to twitter.  One benefit is that twitter is one method to announce information relevant to the local User Group.  Another top notch reason is that there are many very intelligent people watching twitter to help answer questions.  There are hashtags for SSRS, SSIS, SQLHelp and other topics.</p>
<p>If you are in a crunch and having a problem &#8211; twitter is often a very fast way to get a solid answer.  Call it an online helpdesk with quality and personality rating very high on the list.</p>
<h3>What benefit have you seen in your career because of twitter?</h3>
<p>Personally, I enjoy the benefit of the new friends and SQLFamily that twitter has exposed.  I sometimes find the time to lurk on twitter and enjoy in the conversation that is taking place.</p>
<p>Through the conversations that are occurring on twitter I find that it gives me a nice break from the work of the day.  It also gives me access to find interesting topics and articles that others have read or written.  But the best part boils back down to SQLFamily.</p>
<p>Check it out sometime &#8211; I think you will find that it is worthwhile.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2010/01/25/tweeting-i-took-the-dive/" rel="bookmark" class="crp_title">Tweeting &#8211; I took the Dive.</a></li><li><a href="http://jasonbrimhall.info/2011/12/17/why-do-i-blog/" rel="bookmark" class="crp_title">Why do I Blog?</a></li><li><a href="http://jasonbrimhall.info/2011/04/29/seize-the-moment/" rel="bookmark" class="crp_title">Seize the Moment</a></li><li><a href="http://jasonbrimhall.info/2010/08/24/sp_whoami/" rel="bookmark" class="crp_title">Sp_whoAmI</a></li><li><a href="http://jasonbrimhall.info/2010/08/24/sssolv-twitter-compliant/" rel="bookmark" class="crp_title">SSSOLV: Twitter Compliant</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1558" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=Vr3A3UZ6APQ:JD5SQ_I1uOY:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=Vr3A3UZ6APQ:JD5SQ_I1uOY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=Vr3A3UZ6APQ:JD5SQ_I1uOY:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=Vr3A3UZ6APQ:JD5SQ_I1uOY:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/Vr3A3UZ6APQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/16/meme15-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing Indexes</title>
		<link>http://jasonbrimhall.info/2012/01/12/missing-indexes/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=missing-indexes</link>
		<comments>http://jasonbrimhall.info/2012/01/12/missing-indexes/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 14:00:02 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[Index Maintenance]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1563</guid>
		<description><![CDATA[SQL Server has means built into it to track possible missing indexes.  This used to be found through the use of the Index Tuning Wizard.  The process has improved over time (you can sort of see that from my April Fools post). As luck would have it, I was recently [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server has means built into it to track possible missing indexes.  This used to be found through the use of the Index Tuning Wizard.  The process has improved over time (you can sort of see that from my <a href="http://jasonbrimhall.info/2011/04/01/indexing-just-got-easy/">April Fools post</a>).</p>
<p>As luck would have it, I was recently asked to help fix a query that was somewhat related to the whole process.  You see, since SQL Server 2005, there are DMOs that help to track metadata related to column and index usage.  And if there a query is repeated enough that doesn&#8217;t have a good matching index, then the engine may think that a new index is needed.  This potential index information is recorded and becomes visible via the DMOs.</p>
<p>The query that I was asked to help fix was a dynamic query within a cursor that read information from the DMOs in order to generate some missing index information.  That particular query was failing for a couple of reasons, but on the same token it gave me an idea to modify and adapt the query to something more in line with what I might use.  After all, the queries that I used were in need of updating and this gets me started in that direction.</p>
<p>First, a little on why the query was failing.  A common problem with dynamic queries is the placement of quotes and having enough quotes in all required locations.  When you start nesting more levels into a dynamic query, the more confusing the quotes can get.  When running into something like this, I like to print the statement that I am trying to build dynamically.  If it doesn&#8217;t look right, then adjust the quotes until it looks right.</p>
<p>The second reason it was failing was a simple oversight.  Whether building dynamic queries or just using variables in your code, make sure you use properly sized variables.  In this case, the dynamic query variable was substantially inadequate.  The use of a print statement also helps to catch these types of errors rather quickly.</p>
<p>There were also a few things that would cause me to not use the original query in any environment.  The first problem is that the script contains a column which is the create statement for each proposed index.  In this create statement, all indexes were given the same name.  That would be a bit of a problem.</p>
<p>The next issue is my concern with the creation of indexes without ensuring that the index is going to provide greater benefit than cost.  Better stated is that the creation of these indexes just because the script spewed them out is no better than to create all of the indexes proposed by the Database Engine Tuning Advisor.  For this, I added a cautionary statement next to every index create statement.</p>
<p>So with these tweaks, as well as other less significant tweaks, here is the query.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">DECLARE</span> AllDatabases <span class="kw1">CURSOR</span> <span class="kw1">FOR</span>
<span class="kw1">SELECT</span> <span class="br0">&#91;</span>name<span class="br0">&#93;</span> <span class="kw1">FROM</span> master.<span class="me1">dbo</span>.<span class="me1">sysdatabases</span> <span class="kw1">WHERE</span> dbid <span class="sy0">&gt;</span> 4
&nbsp;
<span class="kw1">OPEN</span> AllDatabases
&nbsp;
<span class="kw1">DECLARE</span> @DBNameVar <span class="kw1">NVARCHAR</span><span class="br0">&#40;</span>128<span class="br0">&#41;</span>,@<span class="kw1">STATEMENT</span> <span class="kw1">NVARCHAR</span><span class="br0">&#40;</span><span class="kw2">MAX</span><span class="br0">&#41;</span>
&nbsp;
<span class="kw1">FETCH</span> <span class="kw1">NEXT</span> <span class="kw1">FROM</span> AllDatabases <span class="kw1">INTO</span> @DBNameVar
<span class="kw1">WHILE</span> <span class="br0">&#40;</span><span class="kw2">@@FETCH_STATUS</span> <span class="sy0">=</span> 0<span class="br0">&#41;</span>
<span class="kw1">BEGIN</span>
<span class="kw1">PRINT</span> N<span class="st0">'--CHECKING DATABASE '</span> <span class="sy0">+</span> @DBNameVar
<span class="kw1">SET</span> @<span class="kw1">STATEMENT</span> <span class="sy0">=</span> N<span class="st0">'USE ['</span> <span class="sy0">+</span> @DBNameVar <span class="sy0">+</span> <span class="st0">']'</span><span class="sy0">+</span> <span class="kw1">CHAR</span><span class="br0">&#40;</span><span class="nu0">13</span><span class="br0">&#41;</span> <span class="sy0">+</span><span class="st0">';'</span> <span class="sy0">+</span><span class="kw1">CHAR</span><span class="br0">&#40;</span><span class="nu0">13</span><span class="br0">&#41;</span>
<span class="sy0">+</span> N<span class="st0">'
SELECT SO.name
		, ((CONVERT(Numeric(19,6), migs.user_seeks)+CONVERT(Numeric(19,6), migs.unique_compiles))
			*CONVERT(Numeric(19,6), migs.avg_total_user_cost)
			*CONVERT(Numeric(19,6), migs.avg_user_impact/100.0)) AS Impact
		,'</span><span class="st0">'DO NOT AUTO CREATE THESE INDEXES - Creating these indexes could be as bad as blindly using DTA'</span><span class="st0">' as Note
		, '</span><span class="st0">'CREATE NONCLUSTERED INDEX IDX_'</span><span class="st0">' + SO.name +'</span><span class="st0">'_'</span><span class="st0">' + STUFF (
		(SELECT '</span><span class="st0">'_'</span><span class="st0">' + column_name FROM sys.dm_db_missing_index_columns(mid.index_handle) WHERE column_usage IN ('</span><span class="st0">'Equality'</span><span class="st0">','</span><span class="st0">'InEquality'</span><span class="st0">') FOR XML PATH ('</span><span class="st0">''</span><span class="st0">'))
		, 1, 1, '</span><span class="st0">''</span><span class="st0">')  + '</span><span class="st0">' ON ['</span><span class="sy0">+</span>@DBNameVar<span class="sy0">+</span><span class="st0">'].'</span><span class="st0">' + schema_name(SO.schema_id) + '</span><span class="st0">'.'</span><span class="st0">' + SO.name COLLATE DATABASE_DEFAULT + '</span><span class="st0">' ( '</span><span class="st0">' + IsNull(mid.equality_columns, '</span><span class="st0">''</span><span class="st0">') + CASE WHEN mid.inequality_columns IS NULL
		THEN '</span><span class="st0">''</span><span class="st0">'
		ELSE CASE WHEN mid.equality_columns IS NULL
		THEN '</span><span class="st0">''</span><span class="st0">'
		ELSE '</span><span class="st0">','</span><span class="st0">' END + mid.inequality_columns END + '</span><span class="st0">' ) '</span><span class="st0">' + CASE WHEN mid.included_columns IS NULL
		THEN '</span><span class="st0">''</span><span class="st0">'
		ELSE '</span><span class="st0">'INCLUDE ('</span><span class="st0">' + mid.included_columns + '</span><span class="st0">')'</span><span class="st0">' END + '</span><span class="st0">';'</span><span class="st0">' AS CreateIndexStatement
		, mid.equality_columns
		, mid.inequality_columns
		, mid.included_columns
	FROM sys.dm_db_missing_index_group_stats AS migs
		INNER JOIN sys.dm_db_missing_index_groups AS mig
			ON migs.group_handle = mig.index_group_handle
		INNER JOIN sys.dm_db_missing_index_details AS mid
			ON mig.index_handle = mid.index_handle
			AND mid.database_id = DB_ID()
		INNER JOIN sys.objects SO WITH (nolock)
			ON mid.OBJECT_ID = SO.OBJECT_ID
	WHERE (migs.group_handle IN
			(
			SELECT TOP (500) group_handle
			FROM sys.dm_db_missing_index_group_stats WITH (nolock)
			ORDER BY ((CONVERT(Numeric(19,6), migs.user_seeks)+CONVERT(Numeric(19,6), migs.unique_compiles))
				*CONVERT(Numeric(19,6), migs.avg_total_user_cost)
				*CONVERT(Numeric(19,6), migs.avg_user_impact/100.0)) DESC))
		AND OBJECTPROPERTY(SO.OBJECT_ID, '</span><span class="st0">'isusertable'</span><span class="st0">')=1
	ORDER BY 2 DESC , 3 DESC'</span> 
&nbsp;
<span class="kw1">PRINT</span> @<span class="kw1">STATEMENT</span>
<span class="kw1">EXEC</span> <span class="kw3">SP_EXECUTESQL</span> @<span class="kw1">STATEMENT</span>
<span class="kw1">PRINT</span> <span class="kw1">CHAR</span><span class="br0">&#40;</span>13<span class="br0">&#41;</span> <span class="sy0">+</span> <span class="kw1">CHAR</span><span class="br0">&#40;</span>13<span class="br0">&#41;</span>
<span class="kw1">FETCH</span> <span class="kw1">NEXT</span> <span class="kw1">FROM</span> AllDatabases <span class="kw1">INTO</span> @DBNameVar
<span class="kw1">END</span>
&nbsp;
<span class="kw1">CLOSE</span> AllDatabases
<span class="kw1">DEALLOCATE</span> AllDatabases</pre></div></div>
<p>As I post this message, as I tend to do, I am looking for ways to improve upon the query and make it better.  This script should only be used with caution.  It is to provide an insight into potential missing indexes in each database.  A score is assigned to each potential index.  It is with the highest score indexes, that I typically begin analysis to improve performance.  I typically start from a query and execution plan to performance tune.  There are times when an alternative starting point is necessary.  This script is a tool for those times.  Please head the warning that these should be created with extreme caution.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2011/11/01/quick-and-dirty-index-info/" rel="bookmark" class="crp_title">Quick and Dirty Index Info</a></li><li><a href="http://jasonbrimhall.info/2010/03/31/index-info/" rel="bookmark" class="crp_title">Index Info</a></li><li><a href="http://jasonbrimhall.info/2010/01/25/indexes-out-the-windows-ii/" rel="bookmark" class="crp_title">Indexes Out the Window II</a></li><li><a href="http://jasonbrimhall.info/2010/04/27/blob-index-columns/" rel="bookmark" class="crp_title">BLOB Index Columns</a></li><li><a href="http://jasonbrimhall.info/2010/04/21/index-stats-duplication/" rel="bookmark" class="crp_title">Index Stats Duplication</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1563" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=vV4dOy_TMZ8:qq_URdAkd0s:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=vV4dOy_TMZ8:qq_URdAkd0s:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=vV4dOy_TMZ8:qq_URdAkd0s:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=vV4dOy_TMZ8:qq_URdAkd0s:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/vV4dOy_TMZ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/12/missing-indexes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>TSQL Tuesday #26 or #23 – Identity Crisis</title>
		<link>http://jasonbrimhall.info/2012/01/10/tsql-tuesday-26-or-23-identity-crisis/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tsql-tuesday-26-or-23-identity-crisis</link>
		<comments>http://jasonbrimhall.info/2012/01/10/tsql-tuesday-26-or-23-identity-crisis/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 13:00:42 +0000</pubDate>
		<dc:creator>Jason Brimhall</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSSOLV]]></category>
		<category><![CDATA[TSQL Tuesday]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://jasonbrimhall.info/?p=1551</guid>
		<description><![CDATA[The first opportunity of this New Year to participate in TSQLTuesday, we have been invited by David Howard (blog) to take a second shot at a previous TSQLTuesday. This second shot is giving me fits.  I have no clue if it is TSQLTuesday 26 or if it is TSQLTuesday 23. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://photography.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/e/eiffel-tower-fireworks-450237-ga.jpg"><img class="alignright" title="FireworksEiffel" src="http://photography.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/e/eiffel-tower-fireworks-450237-ga.jpg" alt="" width="315" height="450" /></a>The first opportunity of this New Year to participate in TSQLTuesday, we have been invited by David Howard (<a href="http://davidbrycehoward.com/">blog</a>) to take a <a href="http://davidbrycehoward.com/archive/2012/01/tsql-tuesday-026-second-chances/">second shot</a> at a previous TSQLTuesday.</p>
<p>This second shot is giving me fits.  I have no clue if it is <a href="http://davidbrycehoward.com/archive/2012/01/tsql-tuesday-026-second-chances/">TSQLTuesday 26</a> or if it is <a href="http://codegumbo.com/index.php/2011/09/27/tsql2sday-t-sql-tuesday-23early-edition/">TSQLTuesday 23</a>.  Is it some sort of amoeba of both TSQLTuesdays combined?</p>
<p>While I try to figure that out, how about we look at some pictures of what the New Year might have looked like as it was rung in.  Let&#8217;s begin with Paris.</p>
<p>Oooh&#8230;Aaaaahhh&#8230;Those are quite impressive.</p>
<p>Next up on our tour is where a <a href="http://en.wikipedia.org/wiki/Replicas_of_the_Statue_of_Liberty">twin resides for a famous lady</a>.  How did they ring in the New Year in New York City?</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img class="alignnone" title="NY Fireworks 2012" src="http://msnbcmedia.msn.com/j/MSNBC/Components/Photo/_new/pb-111028-liberty-jc-741p.photoblog900.jpg" alt="" width="630" height="630" /></p>
<p>And now, let&#8217;s DBCC Timewarp to the other side of the world.  Here is what you might have seen if you were in Sydney Australia.</p>
<p><a href="http://api.ning.com/files/T9DrUDqEYGWrfCfNq3cPGJd8CLIPoqgdJEzEKBjuG6ZIxoEuTyR8KGGV0ht8ZcL3SjuQgnEpKqRbYMyUdmWm8w__/image2fornewyearsevegallery302135385.jpg"><img class="alignnone" title="Sydney Fireworks" src="http://api.ning.com/files/T9DrUDqEYGWrfCfNq3cPGJd8CLIPoqgdJEzEKBjuG6ZIxoEuTyR8KGGV0ht8ZcL3SjuQgnEpKqRbYMyUdmWm8w__/image2fornewyearsevegallery302135385.jpg" alt="" width="610" height="396" /></a></p>
<p><a href="http://davidbrycehoward.com/archive/2012/01/tsql-tuesday-026-second-chances/"><img class="alignright size-full wp-image-1436" title="TSQL2sDay150x150" src="http://jasonbrimhall.info/wp-content/uploads/2011/11/TSQL2sDay150x150.jpg" alt="" width="150" height="150" /></a>Ahhh.  Yes, that did the trick.  This little diversion sure gave me enough time to think about which TSQLTuesday this is.  Et merci a Stuart Ainsworth (<a href="http://codegumbo.com/">Blog </a>| <a href="http://twitter.com/codegumbo">Twitter</a>).  Le Sujet qu&#8217;il a propose est celui laquelle dont je vais parler ce mois.  Dans le <a href="http://codegumbo.com/index.php/2011/09/27/tsql2sday-t-sql-tuesday-23early-edition/">TSQLTuesday</a> qu&#8217;il a organise, il nous a invite de parler a propos des JOINS.</p>
<p>J&#8217;ai completement rate cet occasion de parler a propos de &#8220;Joins&#8221; en participantes dans TSQLTuesday.  Voyez, TSQLTuesday 23 etait tenu pendant le premier semain au lieu de deuxieme semain ce fois ci.  Et, maintenant, je vais terminer cet article en Anglais.  I was going to write the whole thing in French, but will save that for another time.  I should have a second chance to do that someday.</p>
<p>This second chance, gives me the opportunity to finally talk about a topic that has been on my to-blog list for quite some time.  I hope this post will show some different ways of joining in TSQL.  They are certainly methods I had never considered &#8211; until it was required.</p>
<h3>Business Requirement</h3>
<p>I have some tables that I need query.  One of the tables has lookup information with a bitmask applied to the id field.  Another table references this table but the ids can be a direct match or an indirect match to the id of the lookup table.  For this case, they will always only differ by the value of 1 if the two values do not directly match.  No other match possibility is considered for this example.</p>
<p>Based on this need, the solution dictates some sort of bitwise math.  I have several examples of how a join could be written to accomplish this primary objective.  I am only going to show the possible ways of performing this.  In my environment these all yield the same results and the data is unique and large enough (4.2 million records).  I will compare performance of these different queries in a later post as I demonstrate a query tuning method to drive the query down from nine seconds to 100ms or less.  For the record, I would choose any of queries 5, 6, or 7 for this particular need based on plan cost and performance.</p>
<h3>The JOINS</h3>
<p>First up is the ANSI style INNER Join using addition in one of the conditions as well as an OR to fulfill the second portion of the business requirement.</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 1 -- Join with Or and source+1'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV
		<span class="kw1">INNER</span> Join SourceType US
			<span class="kw1">ON</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span>
				Or PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#41;</span></pre></div></div>
<p>This is probably the easiest to understand and it performs well enough.  Until running into this business requirement, I hadn&#8217;t considered putting an OR in the JOIN conditions.  But it makes sense considering that an AND can be used there.</p>
<p>Next is a NON-ANSI style of JOIN.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 2 -- Non-Ansi Join with Or and source+1'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV, SourceType US
	<span class="kw1">WHERE</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span>
				Or PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#41;</span></pre></div></div>
<p>Through 2008 R2, this works just as well as the ANSI JOIN already shown.  I haven&#8217;t tested in SQL 2012 but I do know that the NON-ANSI syntax of *= (for example) no longer works.  I am not a big fan of this style JOIN because it is far too easy to end up with a Cartesian product.</p>
<p>Another type of JOIN that I like is the use of APPLY.</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 3 -- Cross Apply with Or and source+1'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV
		Cross Apply SourceType US
	<span class="kw1">WHERE</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span>
				Or PPV.<span class="me1">SourceID</span> <span class="sy0">=</span> US.<span class="me1">SourceID</span><span class="sy0">+</span><span class="nu0">1</span><span class="br0">&#41;</span></pre></div></div>
<p>This particular code segment is the equivalent of the first query shown.  This is the last in the set of using basic math and an OR in the JOIN conditions.  The remaining queries all rely on bitwise operations to perform the JOIN.  Again, until this particular need, I had never even considered using a bitwise operation in a JOIN.  First in this series is the NON-ANSI style JOIN.</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 4 -- Non-Ansi with COALESCE and Bit compare'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV, SourceType US
	<span class="kw1">WHERE</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span><span class="sy0">|</span>1 <span class="sy0">=</span> <span class="kw1">COALESCE</span><span class="br0">&#40;</span>US.<span class="me1">SourceID</span><span class="sy0">|</span><span class="nu0">1</span>,Us.<span class="me1">SourceID</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div>
<p>The big change here is in the where clause.  Notice the use of COALESCE and the first comparison value in that COALESCE.  This is called a<a href="http://msdn.microsoft.com/en-us/library/ms186714.aspx"> BITWISE OR</a>.  From <a href="http://msdn.microsoft.com/en-us/library/ms186714.aspx">MSDN</a>: &#8220;The bits in the result are set to 1 if either or both bits (for the current bit being resolved) in the input expressions have a value of 1; if neither bit in the input expressions is 1, the bit in the result is set to 0.&#8221;</p>
<p>So I am comparing the bit values of 1 and the SourceID.  The SourceID from RumorView will create a match meeting the requirements put forth thanks in large part to the BIT OR operation being performed on both sides of the equality in the WHERE clause.  It is also worth mentioning that the COALESCE is completely unnecessary in this query but it I am leaving it as a pseudo reference point for the performance tuning article that will be based on these same queries.</p>
<p>Next on tap is the CROSS Apply version.</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 5 -- Cross with Bit compare'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV
		Cross Apply SourceType US
	<span class="kw1">WHERE</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span><span class="sy0">|</span>1 <span class="sy0">=</span> US.<span class="me1">SourceID</span><span class="sy0">|</span><span class="nu0">1</span><span class="br0">&#41;</span></pre></div></div>
<p>And the last two queries that the optimizer equate to the same query.</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://jasonbrimhall.info/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="tsql" style="font-family:monospace;"><span class="kw1">PRINT</span> <span class="st0">'Query 6 -- Join with Bit compare'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV
		<span class="kw1">INNER</span> Join SourceType US
			<span class="kw1">ON</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span><span class="sy0">|</span>1 <span class="sy0">=</span> US.<span class="me1">SourceID</span><span class="sy0">|</span><span class="nu0">1</span><span class="br0">&#41;</span>
<span class="co1">------</span>
<span class="kw1">PRINT</span> <span class="st0">'Query 7 -- Join with ISNULL and Bit compare'</span>
<span class="co1">------</span>
<span class="kw1">SELECT</span> <span class="kw1">TOP</span> 1000
		PPV.<span class="me1">RumorID</span>,PPV.<span class="me1">PersonRumorID</span>,PPV.<span class="me1">PersonID</span>
		,US.<span class="me1">Source</span>,Us.<span class="me1">SourceID</span>, PPV.<span class="me1">SourceID</span>
	<span class="kw1">FROM</span>	RumorView PPV
		<span class="kw1">INNER</span> Join SourceType US
			<span class="kw1">ON</span> <span class="br0">&#40;</span>PPV.<span class="me1">SourceID</span><span class="sy0">|</span>1 <span class="sy0">=</span> IS<span class="sy0">NULL</span><span class="br0">&#40;</span>US.<span class="me1">SourceID</span><span class="sy0">|</span><span class="nu0">1</span>,Us.<span class="me1">SourceID</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div>
<p>The query optimizer in this case is smart and eliminates the ISNULL.  These two queries use the same exact plan, have the same cost and the same execution statistics.  The version with COALESCE is considered more expensive and takes longer to run than these queries.  It is also important to note that the Cross Apply Join also produces the exact same plan as these two queries.</p>
<h3>Conclusion</h3>
<p>So there you have it.  Many different ways to write the JOIN for this little query.  Performance and results may vary.  It is good to have a few different ways of writing this particular JOIN.  During my testing, it was evident that various methods performed better under different circumstances (such as how the indexes were configured &#8211; which will be discussed in the follow-up article).</p>
<p><em>Notes: Names have been concealed to protect the innocent <img src='http://jasonbrimhall.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .  Also, the fireworks images are all links to external sites.  I have no affiliation with those sites&#8230;disclaimer yada yada yada&#8230;I am not responsible for content on those sites but they can have the credit for the images.</em></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://jasonbrimhall.info/2011/03/10/sql-bitwise-operations/" rel="bookmark" class="crp_title">SQL Bitwise Operations</a></li><li><a href="http://jasonbrimhall.info/2010/03/08/io-io-io/" rel="bookmark" class="crp_title">IO IO IO</a></li><li><a href="http://jasonbrimhall.info/2011/08/19/bitwise-operations/" rel="bookmark" class="crp_title">Bitwise Operations</a></li><li><a href="http://jasonbrimhall.info/2011/04/12/t-sql-tuesday-17-%e2%80%93-apply-knowledge/" rel="bookmark" class="crp_title">T-SQL Tuesday #17 – APPLY Knowledge</a></li><li><a href="http://jasonbrimhall.info/2011/09/13/t-sql-tuesday-22-%e2%80%93-data-presentation/" rel="bookmark" class="crp_title">T-SQL Tuesday #22 – Data Presentation</a></li></ul></div> <img src="http://jasonbrimhall.info/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1551" width="1" height="1" style="display: none;" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=n-xN6CTR-gU:lF3C3QsSv1w:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=n-xN6CTR-gU:lF3C3QsSv1w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/SqlRnnr?a=n-xN6CTR-gU:lF3C3QsSv1w:3QFJfmc7Om4"><img src="http://feeds.feedburner.com/~ff/SqlRnnr?i=n-xN6CTR-gU:lF3C3QsSv1w:3QFJfmc7Om4" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/SqlRnnr/~4/n-xN6CTR-gU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jasonbrimhall.info/2012/01/10/tsql-tuesday-26-or-23-identity-crisis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 3.695 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-04 12:57:01 -->

