<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Sean Decker - SQL Fundamentals</title>
	<atom:link href="http://seandecker.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://seandecker.wordpress.com</link>
	<description>SQL Server 2000, 2005, 2008, Issues, Resolutions, and Comments.</description>
	<lastBuildDate>Thu, 05 Feb 2009 14:57:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='seandecker.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b304c9eaa3b8cfb95d7ab46dbe5fe8ee?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Sean Decker - SQL Fundamentals</title>
		<link>http://seandecker.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://seandecker.wordpress.com/osd.xml" title="Sean Decker - SQL Fundamentals" />
	<atom:link rel='hub' href='http://seandecker.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Create SQL Snapshot Backup to Document Change Process</title>
		<link>http://seandecker.wordpress.com/2009/02/05/create-sql-snapshot-backup-to-document-change-process/</link>
		<comments>http://seandecker.wordpress.com/2009/02/05/create-sql-snapshot-backup-to-document-change-process/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 12:13:41 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[Snapshot Backups]]></category>
		<category><![CDATA[SQL Backups]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=499</guid>
		<description><![CDATA[Let&#8217;s get the disclaimer out of the way right up front.  This article is not intended to be used in place of a Production grade backup solution.  It can be used in conjunction, with your regular backup rotation, but if you truly care &#8230; <a href="http://seandecker.wordpress.com/2009/02/05/create-sql-snapshot-backup-to-document-change-process/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=499&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<address></address>
<p><span style="color:#888888;"><span style="color:#000000;">L</span><span style="color:#000000;"><span style="color:#000000;">e</span>t&#8217;s get the disclaimer out of the way right up front.  This article is not intended to be used in place of a Production grade backup solution.  It can be used in conjunction, with your regular backup rotation, but if you truly care about the database and its contents, please, refer to books on-line or read this </span></span><span style="text-decoration:underline;"><a title="Introduction to Backup and Restore Strategies in SQL Server" href="http://msdn.microsoft.com/en-us/library/ms191239(SQL.90).aspx" target="_blank"><span style="color:#000000;"><span style="color:#0000ff;">I</span><span style="color:#0000ff;"><span style="color:#0000ff;">n</span>troduction to Backup and Restore Strategies in SQL Server</span></span></a></span><span style="color:#0000ff;">.</span></p>
<p><span style="color:#000000;">If you already know all that and want a quick and dirty way to test database modifications or statements in a development environment&#8230;proceed. </span></p>
<p><span style="color:#000000;">While not a developer by trade&#8230;there are circumstances which call for me to wear a different hat.  When that happens&#8230;I typically have to develop, and document, an entire change process.  No different than &#8220;a real developer&#8221;.  The steps are then submitted to a change review board, approved, scheduled, and applied to our production environment.</span></p>
<p><span style="color:#000000;">Going in, I have an idea how it will go.  As the process unfolds, undoubtedly something will occur, or reveal itself, that I hadn&#8217;t thought of and the documentation changes a bit&#8230;with each iteration.</span></p>
<p><span style="color:#000000;">Back in the day&#8230;when we had to walk both ways, uphill, in the snow, to school&#8230;we had to do a backup to disk, run through the changes, document the process, restore the database&#8230;and then do it all over again.  The backup and restore process, with a database of any size, can take a fair amount of time.</span></p>
<p><span style="color:#000000;">Enter &#8221;<strong>SQL Snapshot Backups</strong>&#8221; &#8211; While the dress rehearsals, today, haven&#8217;t changed much&#8230;the backup and restore process has.  Instead of it taking minutes or hours&#8230;taking a snapshot backup or reverting to a previous one takes seconds.  Since each run-thru is that much quicker&#8230;you can focus on getting the process and documentation right.</span></p>
<p><span style="color:#000000;">The syntax below can be used to create a Snapshot of &#8220;Adventureworks&#8221;.  A couple catches&#8230;the NAME is the logical name, of the data file, within the database and the path to the FILENAME, you specify, must exist.</span></p>
<address></address>
<h4><span style="font-size:x-small;color:#008000;">&#8211;Create a database snapshot </span></h4>
<address><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">CREATE</span></span></span></address>
<address><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">DATABASE </span><span style="font-size:x-small;"> Adventureworks_snapshot<span style="font-size:x-small;"> </span></span></span></span></address>
<address><span style="font-size:x-small;color:#0000ff;">ON</span><span style="font-size:x-small;"> <span style="font-size:x-small;"> </span></span></address>
<address><span style="font-size:x-small;color:#808080;">(</span></address>
<address><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;">NAME</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> <span style="font-size:x-small;">AdventureWorks_Data</span></span></span></span></address>
<address><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#808080;">, </span></span></span><span style="font-size:x-small;"><span style="font-size:x-small;"><span style="font-size:x-small;color:#0000ff;">FILENAME</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> <span style="color:#ff0000;">&#8216;</span></span><span style="font-size:x-small;color:#ff0000;"><span style="color:#ff0000;">D</span>:\Backup\Adventureworks_Snapshot&#8217;</span></span></span></address>
<address><span style="font-size:x-small;color:#808080;">)</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">AS</span><span style="font-size:x-small;"> SNAPSHOT </span><span style="font-size:x-small;color:#0000ff;">OF</span><span style="font-size:x-small;">Adventureworks</span></address>
<address></address>
<address></address>
<p> </p>
<p>The Snapshot should then be visible in the Database Snapshots folder: <img class="alignleft size-full wp-image-538" title="snapshot13" src="http://seandecker.files.wordpress.com/2009/02/snapshot13.jpg?w=217&#038;h=65" alt="snapshot13" width="217" height="65" /></p>
<p> </p>
<p> </p>
<p><span style="color:#000000;">Once you have confirmed the Snapshot has been taken you can run through your modifications, document, and verify your process.  Should you need to, use the syntax below to revert back to the state the database was in when the snapshot was initially taken&#8230;and run through it again.</span></p>
<h4> <span style="font-size:x-small;color:#008000;">&#8211; Reverting AdventureWorks to AdventureWorks_snapshot</span></h4>
<address>USE</address>
<address><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#000000;">master</span><span style="font-size:x-small;color:#808080;">;</span></span><span style="font-size:x-small;"><span style="font-size:x-small;"> </span></span></address>
<address><span style="font-size:x-small;color:#0000ff;">RESTORE </span><span style="font-size:x-small;color:#0000ff;">DATABASE</span><span style="font-size:x-small;color:#000000;">Adventureworks </span></address>
<address><span style="font-size:x-small;color:#0000ff;">from </span><span style="font-size:x-small;">DATABASE_SNAPSHOT </span><span style="font-size:x-small;color:#808080;">=</span><span style="font-size:x-small;"> <span style="color:#ff0000;">&#8216;</span></span><span style="font-size:x-small;color:#ff0000;">Adventureworks_snapshot&#8217;</span><span style="font-size:x-small;color:#808080;">;</span></address>
<address><span style="font-size:x-small;">GO</span></address>
<address></address>
<address></address>
<p> </p>
<p>When you are comfortable with your results and have the change process fully documented you can use the following to delete the snapshot:</p>
<p> </p>
<address> <span style="color:#008000;">&#8211;To Delete AdventureWorks Snapshot</span></address>
<address><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#0000ff;">DROP</span></span></span></address>
<address><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#0000ff;">DATABASE</span></span></span></address>
<address><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;color:#008000;"><span style="font-size:x-small;">Adventureworks_snapshot</span></span></span><br />
</address>
<address></address>
<address> </address>
<address></address>
<p>The following is a link to an article that contains some <span style="color:#0000ff;"><span style="text-decoration:underline;"><a title="Creating a Database Snapshot" href="http://msdn.microsoft.com/en-us/library/ms190677(SQL.90).aspx" target="_blank"><span style="color:#0000ff;">B</span></a></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="text-decoration:underline;"><a title="Creating a Database Snapshot" href="http://msdn.microsoft.com/en-us/library/ms190677(SQL.90).aspx" target="_blank"><span style="color:#0000ff;">est Practices for Creating Database Sna</span><span style="color:#0000ff;">pshots</span></a></span></span> </span>if you would like more information.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/499/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/499/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/499/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=499&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/02/05/create-sql-snapshot-backup-to-document-change-process/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/02/snapshot13.jpg" medium="image">
			<media:title type="html">snapshot13</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Queries That Identify Unused Indexes &#8211; Finders Keepers!</title>
		<link>http://seandecker.wordpress.com/2009/01/30/sql-queries-that-identify-unused-indexes-finders-keepers/</link>
		<comments>http://seandecker.wordpress.com/2009/01/30/sql-queries-that-identify-unused-indexes-finders-keepers/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 14:10:23 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Finding Unused Indexes]]></category>
		<category><![CDATA[SQL Server DMVs]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=387</guid>
		<description><![CDATA[I&#8217;ve always found indexing, and performance tuning in general, extremely interesting.  Trying to understand how it all works&#8230;and works so well&#8230;has been a great part of the journey.  That whole &#8220;Is it an art or is it a science&#8221; thing&#8230;   Well&#8230;I think &#8230; <a href="http://seandecker.wordpress.com/2009/01/30/sql-queries-that-identify-unused-indexes-finders-keepers/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=387&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always found indexing, and performance tuning in general, extremely interesting.  Trying to understand how it all works&#8230;and works so well&#8230;has been a great part of the journey.  That whole &#8220;Is it an art or is it a science&#8221; thing&#8230;  </p>
<p>Well&#8230;I think I may have had some kind spiritual awakening or something here recently because part of the mystery of tuning and maintaining indexes has been revealed to me.</p>
<p>Okay&#8230;maybe they weren&#8217;t that kind of a revelations&#8230;but the the two queries below and the paths they led me down were very enlightening.  I am re-publishing them here, not to take credit for them, but because they, or some variation of them, will remain part of my toolkit.</p>
<address>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</address>
<address><strong>This first query was <span style="color:#0000ff;"><a title="Updated Unused Index Query" href="http://statisticsio.com/Home/tabid/36/articleType/ArticleView/articleId/320/Updated-Unused-Index-Query.aspx" target="_blank">posted by </a></span></strong><span style="color:#0000ff;"><strong><span style="color:#0000ff;"><a title="Updated Unused Index Query" href="http://statisticsio.com/Home/tabid/36/articleType/ArticleView/articleId/320/Updated-Unused-Index-Query.aspx" target="_blank">Jason Massie</a></span></strong></span><strong><span style="color:#0000ff;"><a title="Updated Unused Index Query" href="http://statisticsio.com/Home/tabid/36/articleType/ArticleView/articleId/320/Updated-Unused-Index-Query.aspx" target="_blank"> </a></span>- a.k.a. StatisticsIO</strong></address>
<address>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</address>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">SELECT </span><span style="font-size:10pt;">objectname<span style="color:gray;">=</span><span style="color:fuchsia;">OBJECT_NAME</span><span style="color:gray;">(</span>s<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span><span style="color:gray;">)</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">,</span><span style="font-size:10pt;">indexname<span style="color:gray;">=</span>i<span style="color:gray;">.</span><span style="color:blue;">name</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">,</span><span style="font-size:10pt;"> i<span style="color:gray;">.</span>index_id   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">,</span><span style="font-size:10pt;"> reads<span style="color:gray;">=</span>user_seeks <span style="color:gray;">+</span> user_scans <span style="color:gray;">+</span> user_lookups   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">,</span><span style="font-size:10pt;"> writes <span style="color:gray;">=</span>  user_updates   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">,</span><span style="font-size:10pt;"> p<span style="color:gray;">.</span>rows</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">FROM</span><span style="font-size:10pt;"> <span style="color:green;">sys.dm_db_index_usage_stats</span> s <span style="color:gray;">JOIN</span> <span style="color:green;">sys.indexes</span> i  </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">ON</span><span style="font-size:10pt;"> i<span style="color:gray;">.</span>index_id <span style="color:gray;">=</span> s<span style="color:gray;">.</span>index_id <span style="color:gray;">AND</span> s<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span> <span style="color:gray;">=</span> i<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span>   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">JOIN</span><span style="font-size:10pt;"> <span style="color:green;">sys.partitions</span> p <span style="color:blue;">ON</span> p<span style="color:gray;">.</span>index_id <span style="color:gray;">=</span> s<span style="color:gray;">.</span>index_id <span style="color:gray;">AND</span> s<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span> <span style="color:gray;">=</span> p<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">WHERE</span><span style="font-size:10pt;"> <span style="color:fuchsia;">OBJECTPROPERTY</span><span style="color:gray;">(</span>s<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span><span style="color:gray;">, </span><span style="color:red;">&#8216;IsUserTable&#8217;</span><span style="color:gray;">)</span> <span style="color:gray;">=</span> 1   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">AND</span><span style="font-size:10pt;"> s<span style="color:gray;">.</span>database_id <span style="color:gray;">=</span> <span style="color:fuchsia;">DB_ID</span><span style="color:gray;">()</span>   </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">AND</span><span style="font-size:10pt;"> i<span style="color:gray;">.</span>type_desc <span style="color:gray;">=</span> <span style="color:red;">&#8216;nonclustered&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">AND</span><span style="font-size:10pt;"> i<span style="color:gray;">.</span>is_primary_key <span style="color:gray;">=</span> 0</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">AND</span><span style="font-size:10pt;"> i<span style="color:gray;">.</span>is_unique_constraint <span style="color:gray;">=</span> 0</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">AND</span><span style="font-size:10pt;"> p<span style="color:gray;">.</span>rows <span style="color:gray;">&gt;</span> 10000</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">ORDER</span><span style="font-size:10pt;"> <span style="color:blue;">BY</span> reads<span style="color:gray;">,</span> rows <span style="color:blue;">DESC</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">Sums all the reads that have occurred, on an index, and then limits the result set to non-clustered indexes on tables with row counts greater than 10000.  You can quickly see which tables are heavily written to&#8230;but not read from.</p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<address class="MsoNormal"><strong>The query below was <a title="Index Clean-Up Scripts" href="http://sqlfool.com/2009/01/index-clean-up-scripts/" target="_blank"><span style="color:#0000ff;">posted by </span></a></strong><strong><span style="color:#0000ff;"><a title="Index Clean-Up Scripts" href="http://sqlfool.com/2009/01/index-clean-up-scripts/" target="_blank"><span style="color:#0000ff;">Michell Ufford</span></a></span></strong><strong><a title="Index Clean-Up Scripts" href="http://sqlfool.com/2009/01/index-clean-up-scripts/" target="_blank"> </a>- a.k.a SQLFool</strong></address>
<address class="MsoNormal">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</address>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">DECLARE </span><span style="font-size:10pt;">@dbid <span style="color:blue;">INT</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:gray;">,</span>@dbName <span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span>100<span style="color:gray;">);</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;"> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">SELECT </span><span style="font-size:10pt;">@dbid <span style="color:gray;">=</span> <span style="color:fuchsia;">DB_ID</span><span style="color:gray;">()</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:gray;">,</span>@dbName <span style="color:gray;">=</span> <span style="color:fuchsia;">DB_NAME</span><span style="color:gray;">();</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;"> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">WITH </span><span style="font-size:10pt;">partitionCTE <span style="color:gray;">(</span><span style="color:fuchsia;">OBJECT_ID</span><span style="color:gray;">,</span> index_id<span style="color:gray;">,</span> row_count<span style="color:gray;">,</span> partition_count<span style="color:gray;">)</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">AS</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">(</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:blue;">SELECT</span> [OBJECT_ID]</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> index_id</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> <span style="color:fuchsia;">SUM</span><span style="color:gray;">(</span>[ROWS]<span style="color:gray;">)</span> <span style="color:blue;">AS</span> <span style="color:red;">&#8216;row_count&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> <span style="color:fuchsia;">COUNT</span><span style="color:gray;">(</span>partition_id<span style="color:gray;">)</span> <span style="color:blue;">AS</span> <span style="color:red;">&#8216;partition_count&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:blue;">FROM</span> <span style="color:green;">sys.partitions</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:blue;">GROUP</span> <span style="color:blue;">BY</span> [OBJECT_ID]</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> index_id</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">)</span><span style="font-size:10pt;"> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;"> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">SELECT</span><span style="font-size:10pt;"> <span style="color:fuchsia;">OBJECT_NAME</span><span style="color:gray;">(</span>i<span style="color:gray;">.</span>[OBJECT_ID]<span style="color:gray;">)</span> <span style="color:blue;">AS </span>objectName</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> i<span style="color:gray;">.</span><span style="color:blue;">name</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> <span style="color:blue;">CASE</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">WHEN</span> i<span style="color:gray;">.</span>is_unique <span style="color:gray;">=</span> 1 </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                <span style="color:blue;">THEN</span> <span style="color:red;">&#8216;UNIQUE &#8216;</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">ELSE</span> <span style="color:red;">&#8221;</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">          <span style="color:blue;">END</span> <span style="color:gray;">+</span> i<span style="color:gray;">.</span>type_desc <span style="color:blue;">AS</span> <span style="color:red;">&#8216;indexType&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span>ddius<span style="color:gray;">.</span>user_seeks</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span>ddius<span style="color:gray;">.</span>user_scans</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span>ddius<span style="color:gray;">.</span>user_lookups</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span>ddius<span style="color:gray;">.</span>user_updates</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span>cte<span style="color:gray;">.</span>row_count</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> <span style="color:blue;">CASE</span> <span style="color:blue;">WHEN</span> partition_count <span style="color:gray;">&gt;</span> 1 <span style="color:blue;">THEN</span> <span style="color:red;">&#8216;yes&#8217;</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">ELSE</span> <span style="color:red;">&#8216;no&#8217;</span> <span style="color:blue;">END</span> <span style="color:blue;">AS</span> <span style="color:red;">&#8216;partitioned?&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">,</span> <span style="color:blue;">CASE</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">WHEN</span> i<span style="color:gray;">.</span><span style="color:blue;">type</span> <span style="color:gray;">=</span> 2 <span style="color:gray;">And</span> i<span style="color:gray;">.</span>is_unique <span style="color:gray;">=</span> 0</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                <span style="color:blue;">THEN</span> <span style="color:red;">&#8216;Drop Index &#8216;</span> <span style="color:gray;">+</span> i<span style="color:gray;">.</span><span style="color:blue;">name</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                    <span style="color:gray;">+</span> <span style="color:red;">&#8216; On &#8216;</span> <span style="color:gray;">+</span>@dbName </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                    <span style="color:gray;">+</span> <span style="color:red;">&#8216;.dbo.&#8217;</span> <span style="color:gray;">+</span> <span style="color:fuchsia;">OBJECT_NAME</span><span style="color:gray;">(</span>ddius<span style="color:gray;">.</span>[OBJECT_ID]<span style="color:gray;">)</span> <span style="color:gray;">+</span> <span style="color:red;">&#8216;;&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">WHEN</span> i<span style="color:gray;">.</span><span style="color:blue;">type</span> <span style="color:gray;">=</span> 2 <span style="color:gray;">And</span> i<span style="color:gray;">.</span>is_unique <span style="color:gray;">=</span> 1</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                <span style="color:blue;">THEN</span> <span style="color:red;">&#8216;Alter Table &#8216;</span> <span style="color:gray;">+</span>@dbName </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                    <span style="color:gray;">+</span> <span style="color:red;">&#8216;.dbo.&#8217;</span> <span style="color:gray;">+</span> <span style="color:fuchsia;">OBJECT_NAME</span><span style="color:gray;">(</span>ddius<span style="color:gray;">.</span>[OBJECT_ID]<span style="color:gray;">)</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">                    <span style="color:gray;">+</span> <span style="color:red;">&#8216; Drop Constraint &#8216;</span> <span style="color:gray;">+</span> i<span style="color:gray;">.</span><span style="color:blue;">name</span> <span style="color:gray;">+</span> <span style="color:red;">&#8216;;&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">            <span style="color:blue;">ELSE</span> <span style="color:red;">&#8221;</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">          <span style="color:blue;">END</span> <span style="color:blue;">AS</span> <span style="color:red;">&#8216;SQL_DropStatement&#8217;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">FROM</span><span style="font-size:10pt;"> <span style="color:green;">sys.indexes</span> <span style="color:blue;">AS</span> i</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">INNER</span><span style="font-size:10pt;"> <span style="color:gray;">Join</span> <span style="color:green;">sys.dm_db_index_usage_stats </span>ddius</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:blue;">ON</span> i<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span> <span style="color:gray;">=</span>ddius<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">And</span> i<span style="color:gray;">.</span>index_id <span style="color:gray;">=</span>ddius<span style="color:gray;">.</span>index_id</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:gray;">INNER</span><span style="font-size:10pt;"> <span style="color:gray;">Join </span>partitionCTE <span style="color:blue;">AS </span>cte</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:blue;">ON</span> i<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span> <span style="color:gray;">=</span>cte<span style="color:gray;">.</span><span style="color:fuchsia;">OBJECT_ID</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">        <span style="color:gray;">And</span> i<span style="color:gray;">.</span>index_id <span style="color:gray;">=</span>cte<span style="color:gray;">.</span>index_id</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">WHERE </span><span style="font-size:10pt;">ddius<span style="color:gray;">.</span>database_id <span style="color:gray;">=</span>@dbid</span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-family:Book Antiqua;"><span style="font-size:10pt;color:blue;">ORDER</span><span style="font-size:10pt;"> <span style="color:blue;">BY</span> </span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:gray;">(</span>ddius<span style="color:gray;">.</span>user_seeks <span style="color:gray;">+</span>ddius<span style="color:gray;">.</span>user_scans <span style="color:gray;">+</span>ddius<span style="color:gray;">.</span>user_lookups<span style="color:gray;">)</span> <span style="color:blue;">ASC</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"><span style="font-size:10pt;"><span style="font-family:Book Antiqua;">    <span style="color:gray;">,</span> user_updates <span style="color:blue;">DESC</span><span style="color:gray;">;</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">Provides a more granular view.  Not only do you see if an index is being used&#8230;you see how it is being used.  Another cool feature is that the Drop or Alter Index statements are generated for you.</p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">Both of the queries reference the <a title="sys.dm_db_index_usage_stats" href="http://msdn.microsoft.com/en-us/library/ms188755.aspx" target="_blank">sys.dm_db_index_usage_stats</a> DMV, return similar results, and work great! </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left"> </p>
<p class="MsoNormal" style="text-align:left;margin:0;" align="left">Why use both?  You may or may not&#8230;but it&#8217;s not a bad idea to get a second opinion.  In addition, understanding the variations of how the DMV, and its results, can be used is what unlocks some of its mysteries. </p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;">Jason&#8217;s query cuts to the chase.  Are the indexes, on tables of substantial size, being utilized?  You can adjust or add additional threshholds to suit your environment.  This would be a great query to put into a Reporting Services report to keep an eye on some of your heavy hitters.</p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;">Michelle&#8217;s query gives you that extra detail for a more in-depth look.  The fact that the DDL statements are generated is great for documenting any changes you make&#8230;this day and age that is critical.  I suppose you could take it a step further and generate the Create and Alter statements that would reverse those changes too.  Management likes peace of mind&#8230;</p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;">Now&#8230;if you haven&#8217;t subscribed to, and read, <a title="StatisticsIO - A SQL Server Blog by Jason Massie" href="http://statisticsio.com/" target="_blank">Jason Massie&#8217;s</a>, and <a title="SQL Fool - Adventures in SQL Tuning - a blog for the rest of us" href="http://sqlfool.com/" target="_blank">Michelle Ufford&#8217;s</a>, blogs&#8230;go do it&#8230;the path to enlightenment is much shorter that way.</p>
<p class="MsoNormal" style="margin:0;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/387/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=387&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/30/sql-queries-that-identify-unused-indexes-finders-keepers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy SQL Server Client Component Configurations</title>
		<link>http://seandecker.wordpress.com/2009/01/19/copy-sql-server-client-component-configurations/</link>
		<comments>http://seandecker.wordpress.com/2009/01/19/copy-sql-server-client-component-configurations/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 12:06:53 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[SQL Server Configuration]]></category>
		<category><![CDATA[SQL Server Alias]]></category>
		<category><![CDATA[SQL Server Registrations]]></category>
		<category><![CDATA[Template Explorer]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=257</guid>
		<description><![CDATA[I was recently given a new workstation.  Hooray!  Since that happened, a number of the tools I use have to be re-installed and re-configured.  Booooo! The most critical of them all, of course, the SQL Server 2005/2008 Client Components.  If you work in &#8230; <a href="http://seandecker.wordpress.com/2009/01/19/copy-sql-server-client-component-configurations/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=257&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">I was recently given a new workstation.  Hooray! </p>
<p style="text-align:left;">Since that happened, a number of the tools I use have to be re-installed and re-configured.  Booooo!</p>
<p style="text-align:left;">The most critical of them all, of course, the SQL Server 2005/2008 Client Components.  If you work in an environment with multiple Development, UAT,  and Production SQL Servers this can be a drag.  Fortunately, with SQL 2005, or with SQL 2008, some of it&#8217;s not too painful.  Being able to migrate from one installation to the next, quickly, makes it easier to share settings and tools with your fellow DBAs or to copy them to machines you commonly work from to give you a similar landscape. There are several items that I like being able to bring forward from one to the next:</p>
<p style="text-align:left;"><strong><img class="alignleft size-full wp-image-304" title="re-configureimage11" src="http://seandecker.files.wordpress.com/2009/01/re-configureimage11.jpg?w=254&#038;h=256" alt="re-configureimage11" width="254" height="256" />SQL Server Groups and Registrations</strong></p>
<p style="text-align:left;">On the source machine, within SSMS, click &#8220;Ctrl+Alt+G&#8221; to view the Registered Servers. </p>
<p style="text-align:left;"> Right click on &#8220;Database Engine&#8221; (Or any preferred sub-group) and select &#8220;Export&#8230;&#8221;</p>
<p style="text-align:left;"> </p>
<p style="text-align:left;"><img class="alignleft size-full wp-image-317" title="re-configureimage24" src="http://seandecker.files.wordpress.com/2009/01/re-configureimage24.jpg?w=251&#038;h=275" alt="re-configureimage24" width="251" height="275" />Select the &#8220;Database Engine&#8221; to export all registered Servers or select an individual Server Group.  Provide the location and file name the export should be saved to and click Ok.</p>
<p style="text-align:left;"><span style="color:#ff0000;">Warning:</span>  If these are production server registrations, either leave the &#8220;Do not include user name and passwords&#8230;&#8221; option checked or make sure the export is kept in a secure location.</p>
<p style="text-align:left;">Copy the export file to your target machine(s) and &#8220;import&#8221; the Server Registrations in the same manner.</p>
<p style="text-align:left;"><strong><span style="color:#0000ff;">NOTE</span></strong>:  The Server Registration exports ARE NOT interchangeable between SQL 2005 and SQL 2008.</p>
<p style="text-align:left;"><strong>Template Explorer Customizations</strong> &#8211; I have used Template Explorer quite extensively to keep my most commonly used scripts at the ready.  I also maintain a collection of &#8220;troubleshooting&#8221; scripts that can be referenced in an emergency.  It helps with remaining calm, when others may be excited, knowing where to find the scripts you need under pressure.</p>
<p style="text-align:left;">If you have created Templates, and saved them, their default location will be:</p>
<p style="text-align:left;">C:\Documents and Settings\YourUserName\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\Templates\Sql</p>
<p style="text-align:left;">Simply copy the folders and templates from that location on your source machine to your target.</p>
<p style="text-align:left;"><span style="color:#0000ff;"><strong>Recommendation</strong></span>:  Create one or two folders and then creating sub-folders within those to keep your personal scripts organized and separate from those provided.  It makes migrating or sharing them that much easier and reduces the likelyhood that any will be missed.  It&#8217;s cleaner too if you&#8217;re moving from SQL 2005 to SQL 2008.  I also have a &#8220;junk&#8221; folder (Like a drawer) for any scripts I&#8217;m working on that I&#8217;m not worried about keeping yet.</p>
<p style="text-align:left;"><strong>Solution Explorer </strong>- Ditto with Projects you may have created:</p>
<p style="text-align:left;">If you have created Projects, and saved them, their default location will be:</p>
<p style="text-align:left;">C:\Documents and Settings\YourUsername\My Documents\SQL Server Management Studio\Projects</p>
<p style="text-align:left;">Simply copy the folders and Solutions from that location on your source machine to your target.</p>
<p style="text-align:left;"><strong>SQL Server Configuration Alias</strong>- Just like the SQL Server Groups and Registrations, having to recreate the 15 different Alias&#8217; that are defined within SQL Server Configuration Manager can be tedious.  Good news here is that they can be quickly exported and imported.  A bonus is that Configuration Alias&#8217; ARE interchangeable between SQL 2005 and SQL 2008.</p>
<p style="text-align:left;"><span style="color:#ff0000;">Warning</span>:  The steps below involve making changes with your registry.  Proceed with caution&#8230;at your own risk <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align:left;">Launch &#8220;Regedt32&#8243; and browse to, and highlight, the following location: </p>
<p style="text-align:left;">&#8220;HKey_Local_Machine\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo&#8221;</p>
<p style="text-align:left;"><img class="alignleft size-full wp-image-361" title="re-configureimage53" src="http://seandecker.files.wordpress.com/2009/01/re-configureimage53.jpg?w=455&#038;h=186" alt="re-configureimage53" width="455" height="186" /></p>
<p style="text-align:left;"> </p>
<p style="text-align:left;">From the menu select &#8220;File-&gt;Export&#8221;.  Provide the path and file name on your source machine.  Copy that file to your target machine and double-click on it.  It will ask you if you want to import it&#8230;say yes!</p>
<p style="text-align:left;">If you have other suggestions or features you migrate please let me know.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/257/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/257/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/257/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=257&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/19/copy-sql-server-client-component-configurations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/re-configureimage11.jpg" medium="image">
			<media:title type="html">re-configureimage11</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/re-configureimage24.jpg" medium="image">
			<media:title type="html">re-configureimage24</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/re-configureimage53.jpg" medium="image">
			<media:title type="html">re-configureimage53</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Select to Return Dynamic SQL Statements</title>
		<link>http://seandecker.wordpress.com/2009/01/14/using-select-to-return-dynamic-sql-statements/</link>
		<comments>http://seandecker.wordpress.com/2009/01/14/using-select-to-return-dynamic-sql-statements/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 19:32:28 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[Transact SQL Syntax]]></category>
		<category><![CDATA[Dynamic Result Sets]]></category>
		<category><![CDATA[Dynamic SQL]]></category>
		<category><![CDATA[SQL Syntax]]></category>
		<category><![CDATA[Transact SQL]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=48</guid>
		<description><![CDATA[Building Select, Update, Insert Statements Dynamically with Select. <a href="http://seandecker.wordpress.com/2009/01/14/using-select-to-return-dynamic-sql-statements/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=48&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#000000;">I&#8217;ve always thought this was pretty slick&#8230;</span></p>
<p><span style="color:#000000;">We&#8217;ve all gone into Query Analyzer or SSMS and ran select, insert, or update  statements.  You write the statement, hit execute, and it returns the data or performs the action.  </span></p>
<p><span style="color:#000000;">What we&#8217;re doing here is no different <em>except</em> that we are actually going to use the SELECT statement to build the statements that we eventually want to capture and run.</span></p>
<p><span style="color:#0000ff;"><span style="color:#000000;">The <span style="color:#0000ff;">SELECT</span> statement below simply returns the string you see between the single quotes:</span></span></p>
<p><span style="color:#0000ff;"><span style="color:#000000;"><span style="color:#000000;"><img class="alignnone size-full wp-image-202" title="dynamicsqlpic1-011420091" src="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic1-011420091.jpg?w=500&#038;h=111" alt="dynamicsqlpic1-011420091" width="500" height="111" /></span></span></span></p>
<p><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#000000;">Lets take it a bit further.  The next image shows that we have modified the string, a bit, by adding a where clause to it.  We&#8217;ve also appended a variable (EmployeeID), a FROM clause, and a WHERE Clause to the end of the statement.  What we end up with are the three individual, select statements, shown, with the explicit EmployeeID dynamically tacked onto the end.</span></span></span></span></span></p>
<p><span style="color:#ff0000;"><img class="alignnone size-full wp-image-205" title="dynamicsqlpic2-01142009" src="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic2-01142009.jpg?w=500&#038;h=167" alt="dynamicsqlpic2-01142009" width="500" height="167" /></span></p>
<p><span style="color:#000000;">You can then copy those statements into the SSMS window and execute them.</span></p>
<p><span style="color:#000000;">Admittedly, those examples are probably only useful <em>as examples, </em>but they illustrate a point.  We can use the SELECT statement to build, and more importantly SEE, the statements that we&#8217;re going to run.</span></p>
<p><span style="color:#000000;">Let&#8217;s make it an UPDATE statement:</span> </p>
<p><img class="alignnone size-full wp-image-233" title="dynamicsqlpic3-01142009" src="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic3-01142009.jpg?w=500&#038;h=188" alt="dynamicsqlpic3-01142009" width="500" height="188" /></p>
<p>Now, looking at the two resulting update statements, we can clearly see that we are about to give our two DBAs ten hours more vacation than anyone else in The Firm.  They clearly deserve it.  Simply run those two statements we&#8217;re off to Hawaii <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><span style="color:#000000;"><span style="color:#000000;">Sometimes being a DBA means covering your tracks.  Actually, that&#8217;s one of the prime directives.  Covering your tracks can mean taking backups, verifying proper permissions are in place, making sure maintenance jobs are running, etc.  In this case, covering your tracks can mean &#8220;Knowing, and being able to document, the statements and parameters that are about to be executed&#8221;.  If I go to the trouble to build the statement&#8230;I will typically save it, and the results, for reference.  It may come in handy in the future too.</span></span></p>
<p> This technique can also be usefull when t<span style="color:#000000;">roubleshooting failed insert or update statements.  If you&#8217;re not dealing too many rows you can quickly scan them or run them in batches to narrow in on the culprit.  </span> </p>
<p><span style="font-size:x-small;color:#ff0000;"><span style="color:#000000;"><span style="font-size:x-small;color:#ff0000;"><span style="color:#000000;">The examples above use the &#8220;Adventureworks&#8221; database that Microsoft provides for practicing and tutorials.  It&#8217;s not installed by default (Like Northwind and Pubs used to be for SQL 2000) so if you have SQL 2005 installed and want the AdventureWorks database, to practice in, you can down load it here at <a title="Codeplex SQL 2005 Sample Downloads" href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004" target="_blank"><span style="color:#000000;">Codeplex</span></a></span><span style="color:#000000;">. </span></span></span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=48&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/14/using-select-to-return-dynamic-sql-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic1-011420091.jpg" medium="image">
			<media:title type="html">dynamicsqlpic1-011420091</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic2-01142009.jpg" medium="image">
			<media:title type="html">dynamicsqlpic2-01142009</media:title>
		</media:content>

		<media:content url="http://seandecker.files.wordpress.com/2009/01/dynamicsqlpic3-01142009.jpg" medium="image">
			<media:title type="html">dynamicsqlpic3-01142009</media:title>
		</media:content>
	</item>
		<item>
		<title>Contributing Through Others&#8230;</title>
		<link>http://seandecker.wordpress.com/2009/01/10/contributing-through-others/</link>
		<comments>http://seandecker.wordpress.com/2009/01/10/contributing-through-others/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 22:32:54 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=117</guid>
		<description><![CDATA[We all know that with technology, and SQL Server in particular, it is a, never ending, educational journey.  Along the way I have encountered, solved, and forgotten how I solved, more issues than I care to admit.  That forgotten part &#8230; <a href="http://seandecker.wordpress.com/2009/01/10/contributing-through-others/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=117&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#0000ff;">We all know that with technology, and SQL Server in particular, it is a, never ending, educational journey.  Along the way I have encountered, solved, <em>and forgotten how I solved</em>, more issues than I care to admit.  That <em>forgotten </em>part may only apply to me <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  but that is part of why I started this blog. </span></p>
<p><span style="color:#ff0000;">How many times have you <em>wished you would have documented that</em>?</span></p>
<p><span style="color:#0000ff;">One of the greatest assets a DBA can have is their toolkit.  What tools are in it may vary widely with experience, knowledge, and preference, but it is up to each of us to keep them sharp, organized, and to continue to look for new ones.  <span style="color:#0000ff;">Going forward, and reaching as far back as I can, that&#8217;s what I&#8217;m doing here.</span></span></p>
<p><span style="color:#ff0000;">Build YOUR toolkit!</span></p>
<p><span style="color:#0000ff;">The title of this post is &#8220;<strong>Contributing Through Others&#8230;</strong>&#8220;.  That phrase comes from a talent developement model that we use at our firm.  It deals with &#8220;Leading and Developing Others&#8221;, &#8220;Mentoring&#8221; and being an &#8220;idea leader&#8221;.  While that&#8217;s one of the loooooooooong term goals of this blog&#8230;it&#8217;s not so much what this post is about.  </span></p>
<p><span style="color:#0000ff;">Today, this is more of a quick tribute to those that have mentored and contributed to and through me&#8230;</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=117&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/10/contributing-through-others/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
		<item>
		<title>Re-Associate An Orphaned SQL User With SQL Login</title>
		<link>http://seandecker.wordpress.com/2009/01/09/re-associate-an-orphaned-sql-database-user-with-sql-login/</link>
		<comments>http://seandecker.wordpress.com/2009/01/09/re-associate-an-orphaned-sql-database-user-with-sql-login/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 16:24:26 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Security; SQL Permissions]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=86</guid>
		<description><![CDATA[If you ever have the need to move a SQL Server Database from one server or instance to the next then you may come accross orphaned SQL Users.  e.g.  The User is present in the database, but it is no &#8230; <a href="http://seandecker.wordpress.com/2009/01/09/re-associate-an-orphaned-sql-database-user-with-sql-login/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=86&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#0000ff;">If you ever have the need to move a SQL Server Database from one server or instance to the next then you may come accross orphaned SQL Users.  e.g.  The User is present in the database, but it is no longer associated with the SQL Login on the Server.</span></p>
<p><span style="color:#0000ff;">When that happens you have a couple of options.  You can delete the database user, re-add them, re-grant the appropriate role or rights, and be on your way.  It gets a bit more complicated, though, when the user owns schema(s) in the database.  If you try to delete and re-add them you&#8217;ll receive an error similar to the following:</span></p>
<p><span style="color:#000000;">&#8220;Drop failed for User &#8216;sqlusername&#8217;.  An exception occurred while executing a Transact-SQL statement or batch.  The database principal owns a schema in the database, and cannot be dropped.&#8221;</span></p>
<p><span style="color:#0000ff;">In order to get around that error, you would have to temporarily re-assign the owner of the schema(s) to another user in the DB before being able to delete their User Login. </span></p>
<p><span style="color:#0000ff;">In addition to the schemas the user may own, they may have been added to roles within the database, they may even have been granted explicit permissions that you would then have to manually re-produce (If you know what they were).  If that&#8217;s the case, recreating those rights can be a meticulous task.  </span></p>
<p><span style="color:#0000ff;">A much better alternative is to execute a statement very similar to the one shown below:</span></p>
<p><span style="color:#ff0000;">EXEC sp_change_users_login &#8216;UPDATE_ONE&#8217; , &#8216;sqlusername&#8217;, &#8216;sqlloginname&#8217;</span></p>
<p><span style="color:#ff0000;"><span style="color:#0000ff;">  It will re-associate the SQL User with the SQL Login and the Schema(s), Roles, and Permissions are retained.</span></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=86&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/09/re-associate-an-orphaned-sql-database-user-with-sql-login/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
		<item>
		<title>Upgrade Your Applications While Downgrading Your Stress</title>
		<link>http://seandecker.wordpress.com/2009/01/08/upgrade-your-applications-while-downgrading-your-stress/</link>
		<comments>http://seandecker.wordpress.com/2009/01/08/upgrade-your-applications-while-downgrading-your-stress/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 04:22:09 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=51</guid>
		<description><![CDATA[I sat in on the Pain-of-the-Week webcasts with Brent Ozar and Michael Lato today.  Thanks to both for their time and expertise! This weeks feature was titled Upgrade Your Applications While Downgrading Your Stress and covered: Rolling back failed upgrades Migrating data when the &#8230; <a href="http://seandecker.wordpress.com/2009/01/08/upgrade-your-applications-while-downgrading-your-stress/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=51&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#0000ff;">I sat in on the <strong><a title="Pain-of-the-Week webcasts " href="http://www.quest.com/backstage/pow.aspx" target="_blank"><span style="color:#0000ff;">Pain-of-the-Week webcasts </span></a></strong>with </span><a title="Brent Ozar" href="http://www.brentozar.com/" target="_blank"><span style="color:#ff0000;">Brent Ozar</span></a><span style="color:#0000ff;"> and </span><a title="Michael Lato" href="http://datatamer.blogspot.com/" target="_blank"><span style="color:#ff0000;">Michael Lato</span></a><span style="color:#0000ff;"> today.  Thanks to both for their time and expertise!</span></p>
<p><span style="color:#0000ff;">This weeks feature was titled </span><strong><span style="color:#0000ff;">Upgrade Your Applications While Downgrading Your Stress</span></strong><span style="color:#0000ff;"> and covered:</span></p>
<ul type="disc">
<li><span style="color:#0000ff;">Rolling back failed upgrades</span></li>
<li><span style="color:#0000ff;">Migrating data when the schemas are incompatible</span></li>
<li><span style="color:#0000ff;">Managing the upgrade cycle when the applications/databases need to move in lock-step</span></li>
</ul>
<p><span style="color:#0000ff;">Michael led off sharing some of his insights and approaches using native SQL Server  tools.  I really appreciated the different categories that he broke the types of upgrades into and the steps he takes to mitigate risks.  I&#8217;ve taken part in many upgrades and getting a high level view from someone else will only improve my own approach to the next.</span></p>
<p><span style="color:#0000ff;">Brent took over from there and quickly showed a few of the cool features that </span><a title="SQL Litespeed" href="http://www.quest.com/litespeed-for-sql-server/" target="_blank"><span style="color:#ff0000;">SQL Litespeed</span></a><span style="color:#0000ff;"><span style="color:#ff0000;"> </span>has built into it.  Like recovering individual objects from any recent backup or transaction log.  He also showed how you can view all changes, schema or data, who made them and when, and then generated the code that would reverse those changes.  Seemed to be pretty intuitive too.  If you haven&#8217;t seen the tool, are looking for something like it,  it&#8217;s worth the watch!</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=51&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/08/upgrade-your-applications-while-downgrading-your-stress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
		<item>
		<title>Find All SQL Servers On A Network with sqlcmd</title>
		<link>http://seandecker.wordpress.com/2009/01/05/find-all-sql-servers-on-a-network-with-sqlcmd/</link>
		<comments>http://seandecker.wordpress.com/2009/01/05/find-all-sql-servers-on-a-network-with-sqlcmd/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 17:23:29 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[sqlcmd]]></category>
		<category><![CDATA[osql]]></category>
		<category><![CDATA[SQL Command Line]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=33</guid>
		<description><![CDATA[In the event that anyone should ask for it we are compiling a list of All SQL Servers, Databases, and Contacts for each application we support in our environment. We have a central repository, that&#8217;s updated daily, that houses that information.  &#8230; <a href="http://seandecker.wordpress.com/2009/01/05/find-all-sql-servers-on-a-network-with-sqlcmd/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=33&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="color:#0000ff;">In the event that anyone should ask for it <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  we are compiling a list of All SQL Servers, Databases, and Contacts for each application we support in our environment.</span></p>
<p><span style="color:#0000ff;">We have a central repository, that&#8217;s updated daily, that houses that information.  That feed, however, and any documentation we create, is only as good as it is current.  We are human&#8230; and need to periodically review systems to ensure that we collect any that may have slipped through the cracks.  It&#8217;s also not a bad idea to see what&#8217;s out there that you may have forgotten about or were&#8217;nt even aware of&#8230;</span></p>
<p><span style="color:#0000ff;">Either the osql or sqlcmd utilities can be used to list all SQL Instances with the following syntax -</span></p>
<p><span style="color:#ff0000;">osql /L</span></p>
<p><span style="color:#ff0000;">sqlcmd -L</span></p>
<p><span style="color:#0000ff;">While both osql and sqlcmd are currently supported, it&#8217;s worth pointing out that the sqlcmd utility, was incorporated into SQL 2005, is more feature rich, and should be used going forward.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=33&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/05/find-all-sql-servers-on-a-network-with-sqlcmd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
		<item>
		<title>Grant User the Right to View Database Schema</title>
		<link>http://seandecker.wordpress.com/2009/01/02/grant-user-the-right-to-view-database-schema/</link>
		<comments>http://seandecker.wordpress.com/2009/01/02/grant-user-the-right-to-view-database-schema/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 20:03:20 +0000</pubDate>
		<dc:creator>Sean Decker</dc:creator>
				<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://seandecker.wordpress.com/?p=20</guid>
		<description><![CDATA[While we normally frown upon granting backend access to our Production SQL Servers we have, on occasion, had a need to allow users to veiw the schema for objects within our Production databases.    Example 1:  We have a &#8220;reporting&#8221; &#8230; <a href="http://seandecker.wordpress.com/2009/01/02/grant-user-the-right-to-view-database-schema/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=20&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">While we normally frown upon granting backend access to our Production SQL Servers we have, on occasion, had a need to allow users to veiw the schema for objects within our Production databases.  </span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><strong>Example 1:</strong>  We have a &#8220;reporting&#8221; database that is refreshed nightly from a copy of our Production DB.  Report writers need to be able to veiw the table definitions to know which fields are available to them to build their reports.  </span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"><strong>Example 2:  </strong>Errors were being generated in our production environment and they were believed to be related to improper versions of a couple of stored procedures having been released.  In order to do a schema comparison, quickly, between our development and production environments, to ensure all differences were corrected, we temporarily granted a developer &#8220;View Definition&#8221; access to allow them to perform a schema comparison.</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="color:#0000ff;">Use the statement below to Grant User the Right to View Database Schema -</span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="color:#ff0000;"><span style="font-size:10pt;font-family:&quot;">GRANT</span><span style="font-size:10pt;font-family:&quot;"> VIEW DEFINITION ON DATABASE::<span style="color:#000000;">DBName</span> TO <span style="color:#000000;">UserName/RoleName</span></span></span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">It&#8217;s a great way to allow the necessary access without having to grant elevated priveleges.</span></span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/seandecker.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/seandecker.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/seandecker.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=seandecker.wordpress.com&amp;blog=6021448&amp;post=20&amp;subd=seandecker&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://seandecker.wordpress.com/2009/01/02/grant-user-the-right-to-view-database-schema/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/653a9f56e4f4436b6cc459b30248c35f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=R" medium="image">
			<media:title type="html">Sean Decker</media:title>
		</media:content>
	</item>
	</channel>
</rss>
