<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Never Say Never &#187; Indexes</title>
	<atom:link href="http://phelabaum.com/archive/tag/indexes/feed/" rel="self" type="application/rss+xml" />
	<link>http://phelabaum.com</link>
	<description>MS SQL Server Development</description>
	<lastBuildDate>Thu, 29 Sep 2011 02:20:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Create Indexes from the Missing Indexes DMV</title>
		<link>http://phelabaum.com/archive/2010/05/create-indexes-from-the-missing-indexes-dmv/</link>
		<comments>http://phelabaum.com/archive/2010/05/create-indexes-from-the-missing-indexes-dmv/#comments</comments>
		<pubDate>Mon, 24 May 2010 15:43:01 +0000</pubDate>
		<dc:creator>Seth Phelabaum</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[DMV's]]></category>
		<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://phelabaum.com/archive/2010/05/create-indexes-from-the-missing-indexes-dmv/</guid>
		<description><![CDATA[Glenn Berry (Blog) writes a lot of queries to extract information from the system DMV’s.&#160; One of them in particular I found extremely helpful in fixing some of the issues in my system.&#160; I took his query (the CTE at the top) and added some text manipulation to actually generate the create statements for you [...]]]></description>
			<content:encoded><![CDATA[<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" face="Calibri">Glenn Berry (<a href="http://glennberrysqlperformance.spaces.live.com" target="_blank">Blog</a>) writes a lot of queries to extract information from the system DMV’s.&#160; One of them in particular I found extremely helpful in fixing some of the issues in my system.&#160; I took his query (the CTE at the top) and added some text manipulation to actually generate the create statements for you to save you some time.&#160; I had much grander plans for this, but unfortunately I’ve been meaning to post this for over a month now and simply haven’t had time to get back to it, so rather than just let it go by the wayside and never post it, I figured I’d just post what I had now and then possibly post an update sometime in the future if I ever finish it.&#160; </font></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" size="2" face="Calibri"></font></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" face="Calibri">A couple of the known problems right now are:&#160; </font></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" size="2" face="Calibri"></font></span></p>
<ul>
<li>
<div style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" face="Calibri">Index names could already be taken, there’s nothing here that checks to make sure they are unique based on other indexes in your database.</font></span></div>
</li>
<li>
<div style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" face="Calibri">No compression options are taken into account.</font></span></div>
</li>
</ul>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" size="2" face="Calibri"></font></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"><font color="#000000" face="Calibri">That said, I still found this fairly useful and hopefully somebody else will as well.&#160; Thanks again to Glenn for all his excellent work at creating queries to pull information from the DMV’s.</font></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes"></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">;</span><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">WITH</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> I <span style="color: blue">AS </span><span style="color: gray">(
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green; font-size: 10pt; mso-no-proof: yes">&#8211; Missing Indexes current database by Index Advantage
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: green; font-size: 10pt; mso-no-proof: yes">&#8211; This DMV Query written by Glenn Berry
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">SELECT</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> user_seeks <span style="color: gray">*</span> avg_total_user_cost <span style="color: gray">*</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">avg_user_impact <span style="color: gray">*</span> <span style="color: #ff8000">0.01</span><span style="color: gray">)</span> <span style="color: blue">AS</span> [index_advantage]<span style="color: gray">,</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">migs<span style="color: gray">.</span>last_user_seek<span style="color: gray">,</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">mid<span style="color: gray">.</span>[statement] <span style="color: blue">AS</span> [Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">mid<span style="color: gray">.</span>equality_columns<span style="color: gray">,</span> mid<span style="color: gray">.</span>inequality_columns<span style="color: gray">,</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">mid<span style="color: gray">.</span>included_columns<span style="color: gray">,</span>migs<span style="color: gray">.</span>unique_compiles<span style="color: gray">,</span> migs<span style="color: gray">.</span>user_seeks<span style="color: gray">,</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">migs<span style="color: gray">.</span>avg_total_user_cost<span style="color: gray">,</span> migs<span style="color: gray">.</span>avg_user_impact
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">FROM</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_missing_index_group_stats</span> <span style="color: blue">AS</span> migs <span style="color: blue">WITH </span><span style="color: gray">(</span><span style="color: blue">NOLOCK</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">INNER</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> <span style="color: gray">JOIN</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_missing_index_groups</span> <span style="color: blue">AS</span> mig <span style="color: blue">WITH </span><span style="color: gray">(</span><span style="color: blue">NOLOCK</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">ON</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> migs<span style="color: gray">.</span>group_handle <span style="color: gray">=</span> mig<span style="color: gray">.</span>index_group_handle
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">INNER</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> <span style="color: gray">JOIN</span> <span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">dm_db_missing_index_details</span> <span style="color: blue">AS</span> mid <span style="color: blue">WITH </span><span style="color: gray">(</span><span style="color: blue">NOLOCK</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">ON</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> mig<span style="color: gray">.</span>index_handle <span style="color: gray">=</span> mid<span style="color: gray">.</span>index_handle
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">WHERE</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> mid<span style="color: gray">.</span>database_id <span style="color: gray">=</span> <span style="color: fuchsia">DB_ID</span><span style="color: gray">()</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">AND</span> user_seeks <span style="color: gray">*</span> avg_total_user_cost <span style="color: gray">*</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">avg_user_impact <span style="color: gray">*</span> <span style="color: #ff8000">0.01</span><span style="color: gray">)</span> <span style="color: gray">&gt;</span> <span style="color: #ff8000">9000</span> <span style="color: green">&#8211; Set this to Whatever
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">)
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">
<p>&#160;</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">SELECT</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> <span style="color: red">&#8216;CREATE INDEX IX_&#8217;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span>[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">)+</span><span style="color: #ff8000">4</span><span style="color: gray">)+</span><span style="color: #ff8000">3</span><span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">LEN</span><span style="color: gray">(</span>[Database.Schema.Table]<span style="color: gray">)</span> <span style="color: gray">-</span><span style="mso-spacerun: yes">&#160; </span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; color: fuchsia; font-size: 10pt; mso-no-proof: yes">CHARINDEX</span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; color: red; font-size: 10pt; mso-no-proof: yes">&#8216;].['</span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">,</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">)+</span><span style="color: #ff8000">4</span><span style="color: gray">)+</span><span style="color: #ff8000">3</span><span style="color: gray">))
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: red">&#8216;_&#8217;</span> <span style="color: gray">+</span> <span style="color: gray">LEFT(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span>Equality_Columns<span style="color: gray">,</span>inequality_columns<span style="color: gray">),
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">&#8216;['</span><span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">),</span><span style="color: red">']&#8216;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: red">&#8216; &#8216;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: red">&#8216;,&#8217;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: #ff8000">20</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: red">&#8216; ON &#8216;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> [Database.Schema.Table]
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: red">&#8216;(&#8216;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span>equality_columns<span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> equality_columns <span style="color: gray">IS</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL</span> <span style="color: gray">AND</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>inequality_columns <span style="color: gray">IS</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">THEN</span> <span style="color: red">&#8216;,&#8217;</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">ELSE</span> <span style="color: red">&#8221;</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160; </span><span style="color: blue">END
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span>inequality_columns<span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: red">&#8216;)&#8217;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: blue">CASE</span> <span style="color: blue">WHEN</span> included_columns <span style="color: gray">IS</span> <span style="color: gray">NOT</span> <span style="color: gray">NULL</span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">THEN</span> <span style="color: red">&#8216; INCLUDE(&#8216;</span> <span style="color: gray">+</span> included_columns <span style="color: gray">+</span> <span style="color: red">&#8216;)&#8217;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">ELSE</span> <span style="color: red">&#8221;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="mso-spacerun: yes">&#160; </span><span style="color: blue">END</span> CreateStatement<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">&#8216;IX_&#8217;
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: fuchsia">SUBSTRING</span><span style="color: gray">(</span>[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">)+</span><span style="color: #ff8000">4</span><span style="color: gray">)+</span><span style="color: #ff8000">3</span><span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">LEN</span><span style="color: gray">(</span>[Database.Schema.Table]<span style="color: gray">)</span> <span style="color: gray">-</span><span style="mso-spacerun: yes">&#160; </span>
</p>
<p>   </span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; color: fuchsia; font-size: 10pt; mso-no-proof: yes">CHARINDEX</span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">(</span><span style="font-family: &quot;Courier New&quot;; color: red; font-size: 10pt; mso-no-proof: yes">&#8216;].['</span><span style="font-family: &quot;Courier New&quot;; color: gray; font-size: 10pt; mso-no-proof: yes">,</span><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes">[Database.Schema.Table]<span style="color: gray">,
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 5">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">CHARINDEX</span><span style="color: gray">(</span><span style="color: red">&#8216;].['</span><span style="color: gray">,</span>[Database.Schema.Table]<span style="color: gray">)+</span><span style="color: #ff8000">4</span><span style="color: gray">)+</span><span style="color: #ff8000">3</span><span style="color: gray">))
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: gray">+</span> <span style="color: red">&#8216;_&#8217;</span> <span style="color: gray">+</span> <span style="color: gray">LEFT(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(</span><span style="color: fuchsia">REPLACE</span><span style="color: gray">(
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: fuchsia">ISNULL</span><span style="color: gray">(</span>Equality_Columns<span style="color: gray">,</span>inequality_columns<span style="color: gray">),
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">&#8216;['</span><span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">),</span><span style="color: red">']&#8216;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: red">&#8216; &#8216;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: red">&#8216;,&#8217;</span><span style="color: gray">,</span><span style="color: red">&#8221;</span><span style="color: gray">),</span><span style="color: #ff8000">20</span><span style="color: gray">)
</p>
<p>     </span></span></p>
<p style="line-height: normal; margin-bottom: 0pt; mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>IndexName
</p>
<p>   </span></p>
<p class="MsoNormal"><span style="line-height: 115%; font-family: &quot;Courier New&quot;; color: blue; font-size: 10pt; mso-no-proof: yes">FROM</span><span style="line-height: 115%; font-family: &quot;Courier New&quot;; font-size: 10pt; mso-no-proof: yes"> I</span></p>
]]></content:encoded>
			<wfw:commentRss>http://phelabaum.com/archive/2010/05/create-indexes-from-the-missing-indexes-dmv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

