<?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> &#187; Maintenance</title>
	<atom:link href="http://benchmarkitconsulting.com/category/sql-server/maintenance-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://benchmarkitconsulting.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 12:54:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Fail Whale for SSMS and CMS for PBM using PS</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 21:56:50 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[PBM]]></category>
		<category><![CDATA[Policy Based Management]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[PS]]></category>
		<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[SSMS]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=1126</guid>
		<description><![CDATA[Translation: Fail Whale for SQL Server Management Studio and Central Management Server for Policy Based Managment using PowerShell&#8230;. lol simple eh? So this is a Microsoft Connect Item in the making&#8230; I had created a PowerShell script to run a bunch of policies against a list of servers that I defined in a ServerList.txt file.  [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1127" title="fwwwwww" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/09/fwwwwww.png" alt="fwwwwww" width="240" height="180" /></p>
<p>Translation: Fail Whale for SQL Server Management Studio and Central Management Server for Policy Based Managment using PowerShell&#8230;. lol simple eh?</p>
<p>So this is a Microsoft Connect Item in the making&#8230;</p>
<p>I had created a PowerShell script to run a bunch of policies against a list of servers that I defined in a ServerList.txt file.  I decided that I didn&#8217;t like the idea of needing to maintain a text file and instead of storing the Instance Names in a table somewhere I decided to hook into the Central Managment Server.</p>
<p>So I logged into the server that is currently running the SQL Server Agent job that was doing all this using a ServerList.txt file.  I changed the PowerShell Script to point to my CMS server instead and ran the .ps1 directly on the server using &#8220;sqlps F:\PBM\EvaluatePolicies.ps1&#8243;.  The script ran as expected, used my CMS server, and everything was tickidyboo.  Or so I thought&#8230;.</p>
<p>I decided to do my final check and run the SQL Server Agent job itself&#8230; and it failed.</p>
<p><img class="alignnone size-full wp-image-1129" title="toslkdsl" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/09/toslkdsl.jpg" alt="toslkdsl" width="168" height="132" /></p>
<p>Hmmmm that&#8217;s weird&#8230; so I confirmed that the SQL Server Agent account had access to the CMS server and even granted it explicit sysadmin rights (just for my troubleshooting).</p>
<p><strong>FAIL</strong></p>
<p>I started tweeting about the problem and got some immediate advice from @<a href="http://twitter.com/afernandez" target="_blank">afernandez</a>, <a href="http://twitter.com/russjohnson">@russjohnson</a>, <a href="http://twitter.com/wendy_dance">@wendy_dance</a>, and <a href="http://twitter.com/sqlchicken">@SQLChicken</a>.  While none of the advice solved my problem it was great to have some other &#8220;eyes&#8221; reading my problem and confirming the stuff that I had already thought of and tested.</p>
<p>The SQL Server Agent Service Account is a secure account that I don&#8217;t even have access or the password for so I asked for some help from one of our Server Admins for my troubleshooting&#8230; he logged into the server for me and I tried to run the ps1 file&#8230;.</p>
<p><strong>FAIL</strong></p>
<p>So I opened up SSMS and checked if I could connect to the CMS directly&#8230;.</p>
<p><strong><span style="text-decoration: underline;">SOLUTION:  </span></strong>In order to use a PowerShell script to connect to the Central Management Server using the SQL Server Agent the service account that SQL Server Agent is running under must REGISTER the CMS Server through SSMS on the Server that is running the job.</p>
<p>Did you get all that&#8230;. because I had never Remote Desktopped onto the Server using the SQL Server Agent service account and Registered the CMS Server in SSMS using that account when I tried to access the CMS Server through my PowerShell script it failed.</p>
<p>I registered the CMS Server using the SQL Server Agent Service Account and everything started sizzling like bacon on a hot pan.</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Fail+Whale+for+SSMS+and+CMS+for+PBM+using+PS+http://tinyurl.com/npkg83" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/&amp;title=Fail+Whale+for+SSMS+and+CMS+for+PBM+using+PS" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/&amp;title=Fail+Whale+for+SSMS+and+CMS+for+PBM+using+PS" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/&amp;title=Fail+Whale+for+SSMS+and+CMS+for+PBM+using+PS" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/22/failwhaleforssmsandcms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Wiki-Witch of the Quest</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 17:14:22 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Brent Ozar]]></category>
		<category><![CDATA[Restore]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLServerPedia]]></category>
		<category><![CDATA[Wiki]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=1065</guid>
		<description><![CDATA[&#8220;I&#8217;ll Wiki you my pretty&#8230; and your little script too!!&#8221; So I submitted my first Wiki article over at SQLServerPedia: Restoring a User Database to a Different Environment and I have to admit that when I first started thinking about it I was quite concerned about how to do it, whether the script is &#8220;wiki [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1066" title="brewit" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/09/brewit.jpg" alt="brewit" width="220" height="168" /></p>
<p><strong><em>&#8220;I&#8217;ll Wiki you my pretty&#8230; and your little script too!!&#8221;</em></strong></p>
<p>So I submitted my first Wiki article over at SQLServerPedia:</p>
<p><a href="http://sqlserverpedia.com/wiki/Restoring_User_Databases_to_Different_Environments" target="_blank">Restoring a User Database to a Different Environment</a></p>
<p>and I have to admit that when I first started thinking about it I was quite concerned about how to do it, whether the script is &#8220;wiki worthy&#8221;, am I the only one who would find this useful, etc&#8230; So let&#8217;s talk about it</p>
<p><strong>How to do it &#8211; </strong>Well look no further then Brent Ozar to provide an amazing how to video: <a href="http://www.sqlserverpedia.com/wiki/How_To_Help" target="_blank">How to Write and Edit Articles</a></p>
<p><strong>Is my script &#8220;Wiki-Worthy&#8221; &#8211; </strong>This is the great thing about a wiki&#8230; even if your script is a just basic script to make your job easier what it provides is a building block for others to take and grow into something that turns into a more robust solution. </p>
<p><strong>Would Anyone Else Find This Useful &#8211; </strong>Do <strong>YOU</strong> find your script useful?  So what makes you think you&#8217;re so special that others wouldn&#8217;t find it useful or maybe they have a similar script that doesn&#8217;t do as much as what your script does&#8230; maybe it does more and now someone can edit your wiki article to include their contributions.</p>
<p>At the end of the day a wiki article is a great way to not only give something back to the community but it also provides an excellent mechanism to have others edit and contribute their 2 cents into the script or discuss how they solve a similar problem.  If SQL Server has taught me anything it&#8217;s taught me that there are a million ways to solve a problem and the way that YOU solve your problem might work but there might be a better solution out there.</p>
<p>Now if you&#8217;ve thought of submitting a wiki article to SQLServerPedia&#8230; now is the time.  SQLServerPedia is giving away an all expenses paid trip to the PASS Summit for new writers that have never been to the Summit before&#8230;  <a href="http://sqlserverpedia.com/wiki/Contest" target="_blank">Details Here</a></p>
<p>See you in Seattle!!</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=The+Wiki-Witch+of+the+Quest+http://tinyurl.com/mq55m7" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/&amp;title=The+Wiki-Witch+of+the+Quest" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/&amp;title=The+Wiki-Witch+of+the+Quest" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/&amp;title=The+Wiki-Witch+of+the+Quest" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/14/the-wiki-witch-of-the-quest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Yo-Yo Diet For Your Database</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 18:38:44 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=1032</guid>
		<description><![CDATA[Everytime I see a database with both AutoGrow and AutoShrink enabled I cringe.  I don&#8217;t &#8220;snicker&#8221; cause I leave any and all snickering to when someone says the words &#8221;Access Database&#8221;.  See here if you&#8217;re confused. OK so why is having both AutoGrow and AutoShrink enabled on your database such a bad thing&#8230; I mean Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1034" title="gfgfgd" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/09/gfgfgd.jpg" alt="gfgfgd" width="320" height="248" /></p>
<p>Everytime I see a database with both AutoGrow and AutoShrink enabled I cringe.  I don&#8217;t &#8220;snicker&#8221; cause I leave any and all snickering to when someone says the words &#8221;Access Database&#8221;.  <a href="http://benchmarkitconsulting.com/colin-stasiuk/2009/08/27/i-love-getting-stuff-in-the-mail-thanks-brento-and-quest-crew/" target="_blank">See here if you&#8217;re confused.</a></p>
<p>OK so why is having both AutoGrow and AutoShrink enabled on your database such a bad thing&#8230; I mean Microsoft wouldn&#8217;t give us these options unless there was a good reason to use them right? WRONG!!</p>
<p>I&#8217;ll admit that as a safety net, having AutoGrow set on your database is not a bad idea.  The rub here is that with proper capacity planning and Database File Management the &#8220;AutoGrow&#8221; process should <strong><span style="text-decoration: underline;">never</span></strong> actually happen.  I don&#8217;t know about you but I like to know when, where, and how my database files are growing to minimize the amount of fragmentation and potential performance hit. </p>
<p>Let&#8217;s talk about a world where Capacity Planning and Database File Managment doesn&#8217;t exist&#8230; a world where AutoGrow and AutoShrink are both enabled&#8230; a world where if you database needs more space you let SQL Server AutoGrow and if your database has too much space you let SQL Server AutoShrink.  This is a world I don&#8217;t ever want to live in&#8230; EVER</p>
<p>Why is this viscious cycle such a bad idea?</p>
<ul>
<li><strong>Resources</strong> &#8211; If you&#8217;re constantly growing and shrinking your database files there is a potentially significant CPU and IO hit (especially with the shrink) and you&#8217;re going to end up nickel and diming yourself to death. </li>
<li><strong>Fragmentation</strong> &#8211; If you&#8217;re constantly autogrowing and autoshrinking your database files will end up in bits and pieces all over your disk.  If you&#8217;re data is spread out all over the disk think of the additional performance hit in reading that data and combine that with the fact that autoshrinking can cause huge fragmentation in your indexes and that&#8217;s quite a double whammy.</li>
<li><strong>Control</strong> &#8211; If you&#8217;re relying on AutoGrow and AutoShrink to manage your database files you&#8217;re giving away control as to when these operations will execute.  These processes don&#8217;t wait or care about scheduled downtime or maintenance windows&#8230; if SQL Server determines it needs to autogrow or autoshrink it&#8217;s going to do it. </li>
</ul>
<p>At the end of the day when it comes to your Database File Management you want to be a control freak.  You don&#8217;t want to put your database on a yo-yo diet where it&#8217;s constantly growing and shrinking and ending up having a negative impact on it&#8217;s &#8220;metabolism&#8221; (Performance)</p>
<p>There is actually a Microsoft Connect Item by <a href="http://twitter.com/aaronbertrand" target="_blank">Aaron Bertrand</a> to <a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=486614" target="_blank">Deprecate all Shrink Database Options</a>&#8230; join the fight and give this item the 5 star rating it deserves!!</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=The+Yo-Yo+Diet+For+Your+Database+http://tinyurl.com/mkt7j6" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/&amp;title=The+Yo-Yo+Diet+For+Your+Database" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/&amp;title=The+Yo-Yo+Diet+For+Your+Database" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/&amp;title=The+Yo-Yo+Diet+For+Your+Database" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/09/07/the-yo-yo-diet-for-your-database/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>xp_delete_file vs. PowerShell</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 18:56:15 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[delete files]]></category>
		<category><![CDATA[maintenance clean up]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=930</guid>
		<description><![CDATA[So I&#8217;m a firm believer in the KISS theory. No not THAT KISS&#8230; the Keep It Simple Stupid theory. So when it comes to backups&#8230; if I&#8217;m not needing to &#8220;trick them out&#8221; or do anything custom I don&#8217;t have any problems with setting up a nice and easy maintenance plan and calling it a [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m a firm believer in the KISS theory.</p>
<p><img class="alignnone size-full wp-image-931" title="auyauh" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/08/auyauh.jpg" alt="auyauh" width="196" height="184" /></p>
<p>No not THAT KISS&#8230; the Keep It Simple Stupid theory.</p>
<p>So when it comes to backups&#8230; if I&#8217;m not needing to &#8220;trick them out&#8221; or do anything custom I don&#8217;t have any problems with setting up a nice and easy maintenance plan and calling it a day.  I know there are some strong opinions out there that you should avoid Maintenance Plans like the plague and I agree that in some situations that they are not your best option but I don&#8217;t like to write them off altogether.</p>
<p>Sorry&#8230; that went longer then expected&#8230;ok back on topic&#8230;</p>
<p><strong>xp_delete_file</strong>&#8230; So I needed to build a custom backup job because with the size of the database I would get greater performance by backing up to multiple backup files (an option that is not available in a maintenance plan).  Now normally I would just attach the maintenance cleanup task to another maintenance plan but I thought &#8220;Hey&#8230; let&#8217;s get crazy&#8221; I&#8217;m going to click on that View T-SQL Button and see what happens.</p>
<p><img class="alignnone size-full wp-image-932" title="fdfdss" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/08/fdfdss.JPG" alt="fdfdss" width="287" height="334" /></p>
<p>Well isn&#8217;t that easy?</p>
<p><code style="font-size: 12px;"><span style="color:blue">EXECUTE&nbsp;</span><span style="color:black">master.dbo.</span><span style="color:darkred">xp_delete_file&nbsp;</span><span style="color:black">0</span><span style="color:gray">,</span><span style="color:red">N&#39;\\ServerName\Folder&#39;</span><span style="color:gray">,</span><span style="color:red">N&#39;BAK&#39;</span><span style="color:gray">,</span><span style="color:red">&#39;2009-08-13T08:14:17&#39;</span><span style="color:gray">,</span><span style="color:black">1</span></code></p>
<p>Could it REALLY be that simple?</p>
<p>Hey&#8230; what&#8217;s with that &#8220;0&#8243; at the front and the &#8220;1&#8243; at the end?  What are those parameters for?</p>
<p>I BINGed the question (OK I really GOOGLEd it&#8230; sorry Microsoft I just can&#8217;t break my google ties) and found that the first arguement determines if it&#8217;s a backup file or a report file (0 and 1 respectively) and the last arguement determines whether or not to include first level subfolders (0 &#8211; no 1 &#8211; yes)</p>
<p>Great&#8230; it looks like I&#8217;ve found my solution&#8230;.. but wait for it&#8230;&#8230; wait for it&#8230;&#8230;..</p>
<p>ENTER PowerShell&#8230;.</p>
<p> <img class="alignnone size-full wp-image-934" title="pssss_super" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/08/pssss_super.jpg" alt="pssss_super" width="160" height="173" /></p>
<p>(Great picture BTW by <a href="http://blog.theaccidentalgeek.com/post/2007/06/28/PowerShell-to-the-rescue.aspx" target="_blank">Joe Brinkman &#8211; The Accidental Geek</a> )</p>
<p>OK admittedly I&#8217;m one of the 42% on <a href="http://www.brentozar.com/archive/2009/07/july-2009-powershell-poll/" target="_blank">Brent Ozar&#8217;s Powershell Poll </a>that don&#8217;t currently use PowerShell but want to.  So I thought here is my chance&#8230;</p>
<p> I started out simple:</p>
<p>Built myself a nice little .ps1 file with this:</p>
<p><span style="color: #0000ff;">$directory = &#8220;C:\&#8221;<br />
Get-ChildItem $directory</span></p>
<p>Ran that bad boy and low and behold&#8230; I&#8217;m a PowerShell developer <img src='http://benchmarkitconsulting.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So I thought&#8230; let&#8217;s add my network share location for my backup files:</p>
<p><span style="color: #0000ff;">$directory = &#8220;\\servername\folder&#8221;<br />
Get-ChildItem $directory</span></p>
<p>Ran that and I&#8217;m back to being a PowerShell failure:</p>
<p><span style="color: #ff0000;">Get-ChildItem : Cannot find path &#8216;\\servername\folder&#8217; because it does not exist.</span></p>
<p>Turns out you need to map a drive for a network share (or at least that&#8217;s how I solved my problem&#8230; please comment if there is a more elegant solution):</p>
<p><span style="color: #0000ff;">$directory = &#8220;\\ServerName\Folder&#8221;<br />
New-PSDrive -name X -psprovider FileSystem -root $directory<br />
Get-ChildItem X:\</span></p>
<p> Now we&#8217;re cooking with fire <img src='http://benchmarkitconsulting.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next I changed my Get-ChildItem statement to filter only the *.BAK files and I set it to recursively go through subdirectories:</p>
<p><span style="color: #0000ff;">$directory = &#8220;\\ServerName\Folder&#8221;<br />
New-PSDrive -name X -psprovider FileSystem -root $directory<br />
Get-ChildItem X:\ -include *.BAK -recurse</span></p>
<p><span style="color: #000000;">This is getting good now <img src='http://benchmarkitconsulting.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Now I wanted to only get the *.BAK files that are older then 4 hours&#8230; this took some googling to get my syntax right:</span></p>
<p><span style="color: #0000ff;">$directory = &#8220;\\ServerName\Folder&#8221;<br />
New-PSDrive -name X -psprovider FileSystem -root $directory<br />
Get-ChildItem X:\ -include *.BAK -recurse | where {((get-date)-$_.creationTime).hours -ge 4}</span></p>
<p> And finally I wanted to delete these files so we &#8220;pipe in&#8221; a remove-item and we&#8217;re done:</p>
<p><span style="color: #0000ff;">$directory = &#8220;\\ServerName\Folder&#8221;<br />
New-PSDrive -name X -psprovider FileSystem -root $directory<br />
Get-ChildItem X:\ -include *.BAK -recurse | where {((get-date)-$_.creationTime).hours -ge 4} | remove-item -force -recurse</span></p>
<p>And if you wanted to add your transaction log backups as well you could copy/paste your Get-ChildItem and change accordingly</p>
<p><span style="color: #0000ff;">Get-ChildItem X:\ -include *.TRN -recurse | where {((get-date)-$_.creationTime).days -ge 1.5} | remove-item -force -recurse</span></p>
<p>And there you go&#8230; I&#8217;m not sure if this means I&#8217;m now a PowerShell user but I&#8217;m definitely starting to drink the KoolAid for sure.</p>
<p>Enjoy!!</p>
<p><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=xp_delete_file+vs.+PowerShell+http://tinyurl.com/or8h3k" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/&amp;title=xp_delete_file+vs.+PowerShell" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/&amp;title=xp_delete_file+vs.+PowerShell" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/&amp;title=xp_delete_file+vs.+PowerShell" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/08/14/xp_delete_file-vs-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bloated MSDB database</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 15:19:16 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[bloat]]></category>
		<category><![CDATA[bloating]]></category>
		<category><![CDATA[msdb]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=803</guid>
		<description><![CDATA[So how do you drop databases? Do you use a simple DROP DATABASE statement? Do you detach the database and remove the files manually? Do you use the GUI? Run these two quick and dirty queries for me: SELECT COUNT(*) FROM   msdb.dbo.backupset SELECT COUNT(*) FROM   msdb.dbo.backupset WHERE  database_name NOT IN (SELECT name FROM master.dbo.sysdatabases)   So how much of your MSDB database is filled with backup [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-804" title="ierjflks" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/07/ierjflks.jpg" alt="ierjflks" width="127" height="194" /></p>
<p>So how do you drop databases?</p>
<p>Do you use a simple DROP DATABASE statement?</p>
<p>Do you detach the database and remove the files manually?</p>
<p>Do you use the GUI?</p>
<p>Run these two quick and dirty queries for me:</p>
<p><code style="font-size: 12px;"><span style="color:blue">SELECT </span><span style="color:magenta">COUNT</span><span style="color:gray">(*)<br />
</span><span style="color:blue">FROM   </span><span style="color:black">msdb.dbo.backupset</span></code></p>
<p><code style="font-size: 12px;"><span style="color:blue">SELECT </span><span style="color:magenta">COUNT</span><span style="color:gray">(*)<br />
</span><span style="color:blue">FROM   </span><span style="color:black">msdb.dbo.backupset<br />
</span><span style="color:blue">WHERE  </span><span style="color:black">database_name </span><span style="color:gray">NOT </span><span style="color:blue">IN </span><span style="color:gray">(</span><span style="color:blue">SELECT </span><span style="color:black">name </span><span style="color:blue">FROM </span><span style="color:black">master.dbo.sysdatabases</span><span style="color:gray">)</span></code></p>
<p> </p>
<p><img class="alignnone size-full wp-image-805" title="fdlkfldkd" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/07/fdlkfldkd.gif" alt="fdlkfldkd" width="144" height="145" /></p>
<p>So how much of your MSDB database is filled with backup history of databases that have long since been dropped from your instance?</p>
<p>MSDB love and care is not something that usually gets alot of press but if you&#8217;re a stickler for wanting to keep things neat and tidy take a look at the information in your MSDB and whether or not you&#8217;re storing (and backing up) more data then you need to.</p>
<p>Want to rid yourself of some MSDB bloating?</p>
<p><code style="font-size: 12px;"><span style="color:blue">SELECT DISTINCT</span><span style="color:gray">(</span><span style="color:black">database_name</span><span style="color:gray">)<br />
</span><span style="color:blue">FROM   </span><span style="color:black">msdb.dbo.backupset<br />
</span><span style="color:blue">WHERE  </span><span style="color:black">database_name </span><span style="color:gray">NOT </span><span style="color:blue">IN </span><span style="color:gray">(</span><span style="color:blue">SELECT </span><span style="color:black">name </span><span style="color:blue">FROM </span><span style="color:black">master.dbo.sysdatabases</span><span style="color:gray">)</span></code></p>
<p>So now that you have a list of those old databases that still have backup history kicking around&#8230; now what?</p>
<p>Don&#8217;t jump the gun and write a DELETE statement for msdb.dbo.backupset&#8230; what about the other backup tables like backupfile, etc?</p>
<p>Answer: msdb.dbo.sp_delete_database_backuphistory</p>
<p><code style="font-size: 12px;"><span style="color:blue">EXEC&nbsp;</span><span style="color:black">msdb.dbo.</span><span style="color:darkred">sp_delete_database_backuphistory&nbsp;</span><span style="color:#434343">@db_nm&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:red">N&#39;&lt;&lt;DATABASE_NAME&gt;&gt;&#39;</p>
<p></span></code></p>
<p>Using this system stored procedure you&#8217;ll ensure that you&#8217;ve removed all the backup history for the specified database.</p>
<p>(As always, please use with caution)</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Bloated+MSDB+database+http://tinyurl.com/ljtr6r" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/&amp;title=Bloated+MSDB+database" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/&amp;title=Bloated+MSDB+database" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/&amp;title=Bloated+MSDB+database" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/07/07/bloated-msdb-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Databases That Have Not Had a Full Backup in x Days</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 14:59:38 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=757</guid>
		<description><![CDATA[So something that you should do regardless of the alerts, notifications, etc that you have setup is to just have a daily sanity check on your database backups. Sure you don&#8217;t have any failed jobs but what if the job never attempted to run in the first place like it was supposed to? If a [...]]]></description>
			<content:encoded><![CDATA[<p>So something that you should do regardless of the alerts, notifications, etc that you have setup is to just have a daily sanity check on your database backups. Sure you don&#8217;t have any failed jobs but what if the job never attempted to run in the first place like it was supposed to?</p>
<p>If a database fails in the enviroment and no backup is there to recover from does it make a sound?</p>
<p>Well no&#8230; but the users are heard for miles hahaha</p>
<p><img class="alignnone size-full wp-image-760" title="screaming" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/06/screaming.jpg" alt="screaming" width="180" height="179" /></p>
<p>Below is a nice quick sanity check showing all the dbs that have NOT been backed up for X days or have never been backed up at all. </p>
<p><code style="font-size: 12px;"><span style="color:blue">DECLARE&nbsp;</span><span style="color:#434343">@num_of_days&nbsp;</span><span style="color:blue">INT<br />
<br />SET&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:#434343">@num_of_days&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:black">1&nbsp;</p>
<p></span><span style="color:blue">SELECT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:black">A.name</span><span style="color:gray">,&nbsp;</span><span style="color:blue">MAX</span><span style="color:gray">(</span><span style="color:black">B.backup_finish_date</span><span style="color:gray">)&nbsp;</span><span style="color:blue">AS&nbsp;</span><span style="color:red">&#39;LastBackupDateTime&#39;<br />
<br /></span><span style="color:blue">FROM&nbsp;&nbsp;&nbsp;</span><span style="color:black">master.dbo.sysdatabases&nbsp;A&nbsp;</span><span style="color:blue">WITH</span><span style="color:gray">(</span><span style="color:black">NOLOCK</span><span style="color:gray">)&nbsp;&nbsp;</span><span style="color:magenta">LEFT&nbsp;</span><span style="color:gray">OUTER&nbsp;</span><span style="color:blue">JOIN<br />
<br />&nbsp;&nbsp;&nbsp;</span><span style="color:black">msdb.dbo.backupset&nbsp;B&nbsp;</span><span style="color:blue">WITH</span><span style="color:gray">(</span><span style="color:black">NOLOCK</span><span style="color:gray">)&nbsp;</span><span style="color:blue">ON&nbsp;</span><span style="color:black">A.name&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:black">B.database_name<br />
<br /></span><span style="color:blue">WHERE&nbsp;&nbsp;</span><span style="color:gray">(</span><span style="color:black">B.TYPE&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:red">&#39;D&#39;&nbsp;</span><span style="color:gray">OR&nbsp;</span><span style="color:black">B.TYPE&nbsp;</span><span style="color:blue">IS&nbsp;</span><span style="color:gray">NULL)<br />
<br /></span><span style="color:blue">GROUP&nbsp;BY&nbsp;</span><span style="color:black">A.name<br />
<br /></span><span style="color:blue">HAVING&nbsp;</span><span style="color:gray">(</span><span style="color:blue">MAX</span><span style="color:gray">(</span><span style="color:black">B.backup_finish_date</span><span style="color:gray">)&nbsp;&lt;&nbsp;</span><span style="color:magenta">GETDATE</span><span style="color:gray">()&nbsp;-&nbsp;</span><span style="color:#434343">@num_of_days&nbsp;</span><span style="color:gray">OR&nbsp;</span><span style="color:blue">MAX</span><span style="color:gray">(</span><span style="color:black">B.backup_finish_date</span><span style="color:gray">)&nbsp;</span><span style="color:blue">IS&nbsp;</span><span style="color:gray">NULL)&nbsp;<br />
<br /></span><span style="color:blue">ORDER&nbsp;BY&nbsp;</span><span style="color:black">A.name<br />
<br /></span></code></p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=SQL+Databases+That+Have+Not+Had+a+Full+Backup+in+x+Days+http://tinyurl.com/njatlc" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/&amp;title=SQL+Databases+That+Have+Not+Had+a+Full+Backup+in+x+Days" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/&amp;title=SQL+Databases+That+Have+Not+Had+a+Full+Backup+in+x+Days" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/&amp;title=SQL+Databases+That+Have+Not+Had+a+Full+Backup+in+x+Days" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/16/sql-databases-that-have-not-had-a-full-backup-in-x-days/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SQL Server 2005 Edition Upgrade</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 16:30:35 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Edition]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[Upgrade]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=738</guid>
		<description><![CDATA[As most of my posts are inspired by stuff I&#8217;ve been working on or have worked on recently this is no different. A request came in to upgrade a SQL Server 2005 Standard Edition Instance to a SQL Server 2005 Enterprise Edition Instance.  Funny thing is that I&#8217;ve been working with SQL Server 2005 since [...]]]></description>
			<content:encoded><![CDATA[<p>As most of my posts are inspired by stuff I&#8217;ve been working on or have worked on recently this is no different.</p>
<p>A request came in to upgrade a SQL Server 2005 Standard Edition Instance to a SQL Server 2005 Enterprise Edition Instance.  Funny thing is that I&#8217;ve been working with SQL Server 2005 since it&#8217;s release and haven&#8217;t had to do this before&#8230; weird&#8230; so I setup a test box with 2005 STD to play around with and mounted myself a 2005 ENT Edition ISO and ran the GUI setup.</p>
<p>After a bit the wizard told me that in order to upgrade my edition of SQL Server I needed to install via command line and use the <strong>SKUUPGRADE</strong> switch.</p>
<p>So I googled myself some Books Online goodness cause installing SQL from the command line is not something I do everyday LOL and found this:</p>
<p><strong>How to: Install SQL Server 2005 from the Command Prompt<br />
</strong><a href="http://msdn.microsoft.com/en-us/library/ms144259(SQL.90).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms144259(SQL.90).aspx</a></p>
<p> <span style="color: #0000ff;">[SKUUPGRADE]<br />
Use the SKUUPGRADE parameter when upgrading from one edition of SQL Server to another edition of SQL Server.</span></p>
<p><span style="color: #0000ff;"><strong>Important: <br />
If you use the SKUUPGRADE parameter, Setup will remove all hotfix and service pack updates from the SQL Server instance being upgraded. Once the edition upgrade is complete, you must reapply all hotfix and service pack updates.<br />
</strong> </span></p>
<p><span style="color: #0000ff;">To perform an edition upgrade of a default instance of SQL Server (SQL Engine only) via unattended Setup, run the following command using either /qb or /qn:</span></p>
<p><span style="color: #0000ff;">start /wait setup.exe ADDLOCAL=SQL_Engine INSTANCENAME=MSSQLSERVER UPGRADE=SQL_Engine SKUUPGRADE=1 /qb</span></p>
<p><span style="color: #0000ff;">The /qb switch allows display of basic Setup dialog boxes. Error messages are also displayed.</span></p>
<p><span style="color: #0000ff;">The /qn switch suppresses all Setup dialog boxes and error messages. If the /qn switch is specified, all Setup messages, including error messages, are written to Setup log files.</span></p>
<p> </p>
<p> So before doing this I took note of the Service Pack + Hotfix level so that I could reapply them after the edition upgrade was complete.</p>
<p>I ran the script as indicated (after a full backup of course) and it worked like a charm.  After reapplying the service pack + hotfixes required to get me back to the same version the users tested and all went as expected.</p>
<p>Not sure how I avoided doing an edition upgrade in the last 5 years or so but it was fun to do something with SQL that was new to me.</p>
<p>and just in case you missed it&#8230;</p>
<p><span style="color: #0000ff;"><strong>Important: <br />
If you use the SKUUPGRADE parameter, Setup will remove all hotfix and service pack updates from the SQL Server instance being upgraded. Once the edition upgrade is complete, you must reapply all hotfix and service pack updates.</strong></span></p>
<p> </p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=SQL+Server+2005+Edition+Upgrade+http://tinyurl.com/ofg678" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/&amp;title=SQL+Server+2005+Edition+Upgrade" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/&amp;title=SQL+Server+2005+Edition+Upgrade" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/&amp;title=SQL+Server+2005+Edition+Upgrade" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/06/03/sql-server-2005-edition-upgrade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving MSDB &#8211; Notifications via DatabaseMail</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 17:12:09 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DatabaseMail]]></category>
		<category><![CDATA[ENABLE_BROKER]]></category>
		<category><![CDATA[msdb]]></category>
		<category><![CDATA[Notifications]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=655</guid>
		<description><![CDATA[If you&#8217;ve ever moved MSDB and have notifications setup using DatabaseMail then you probably already know what I (re)learned today. If you move MSDB your notifications will stop working.  Why you may ask? It&#8217;s because the ENABLE_BROKER configuration is set to false when you move MSDB.  Now I can&#8217;t seem to find (google) any information [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever moved MSDB and have notifications setup using DatabaseMail then you probably already know what I (re)learned today.</p>
<p>If you move MSDB your notifications will stop working.  Why you may ask?</p>
<p>It&#8217;s because the ENABLE_BROKER configuration is set to false when you move MSDB.  Now I can&#8217;t seem to find (google) any information as to WHY this is (please send comments if you have further info) but in order to get your notifications up and running again you&#8217;ll need to run the following command:</p>
<p>ALTER DATABASE msdb SET ENABLE_BROKER;</p>
<p>If this takes a while to run then chances are you are being blocked by another process (chances are the SQL Server Agent)</p>
<p>If you&#8217;re interested in reading more here is the <a href="http://msdn.microsoft.com/en-us/library/ms345408.aspx" target="_blank">Microsoft BOL Link</a> on moving system databases.</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Moving+MSDB+%26%238211%3B+Notifications+via+DatabaseMail+http://tinyurl.com/c3j6g5" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/&amp;title=Moving+MSDB+%26%238211%3B+Notifications+via+DatabaseMail" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/&amp;title=Moving+MSDB+%26%238211%3B+Notifications+via+DatabaseMail" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/&amp;title=Moving+MSDB+%26%238211%3B+Notifications+via+DatabaseMail" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/20/moving-msdb-notifications-via-databasemail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Corrupt as a Dirty Politican&#8230; breathe and think before acting.</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 14:58:32 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Corrupt]]></category>
		<category><![CDATA[DBCC CHECKDB]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=642</guid>
		<description><![CDATA[So first off I made the &#8220;tempdb&#8221; group in SQLBatman&#8217;s rankings which means I&#8217;m a blogger &#8220;that is on his radar screen right now&#8221;.   He didn&#8217;t say whether or not it was a good radar screen or not but I&#8217;m in there with Jeremiah Peschka and Kendal Van Dyke so I&#8217;ll take it as a compliment for sure. [...]]]></description>
			<content:encoded><![CDATA[<p>So first off I made the &#8220;tempdb&#8221; group in <a href="http://sqlbatman.com/rankings/" target="_blank">SQLBatman&#8217;s rankings</a> which means I&#8217;m a blogger &#8220;that is on his radar screen right now&#8221;.   He didn&#8217;t say whether or not it was a good radar screen or not but I&#8217;m in there with <a href="http://facility9.com/" target="_blank">Jeremiah Peschka</a> and <a href="http://kendalvandyke.blogspot.com/" target="_blank">Kendal Van Dyke</a> so I&#8217;ll take it as a compliment for sure.</p>
<p>Enough touchy feely stuff&#8230; let&#8217;s get to the guts of the post&#8230;</p>
<p><img class="alignnone size-full wp-image-649" title="chickenlittle" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/04/chickenlittle.jpg" alt="chickenlittle" /></p>
<p>OK Chicken Little your database is corrupt and your sky is falling.  You want this dirty feeling gone as quickly as possible.  Before you go and do something crazy like blindly running a repair or detaching a suspect database take some time to do some investigation work to see if you can figure out what is going on.  At the end of the day you normally have 2 options&#8230; try and repair the damage or restore the database from backup. In order to determine which path is best for you you should do some things like running DBCC CHECKDB and looking in the Error Log to try and give yourself some clues as to the extent of the problem.  Check out the Windows Event Log, are there any RAID or disk errors? In the result set of your DBCC CHECKDB you might get 1 error, you might get 100 errors, or it might not even finish if your db is in a really bad state.  If DBCC CHECKDB can&#8217;t run at all then you&#8217;re pretty well looking at recovering from backup. There are some other errors in the CHECKDB output that would usually force you to go back to a backup, things like data purity errors or page header corruption are a couple examples.</p>
<p>An &#8220;easy&#8221; thing that can come out of your CHECKDB output is if a nonclustered index is corrupt.  If the indexid is greater than 1 you can rebuild it offline in SQL Server 2005 or recreate it in SQL Server 2008 and Bob&#8217;s your uncle.  Now this doesn&#8217;t tell you WHY this happened but it will resolve your corrupt index and (hopefully) get you back into the game. </p>
<p>Another example of a &#8220;repairable&#8221; problem is a corrupt page(s).  If you have corrupt pages your first thought could be to try and do a single page restore using a full backup and then applying the subsequent transaction log backups.  What if you only do nightly full backups of your database?  An option in this case is the REPAIR_ALLOW_DATA_LOSS argument in your DBCC CHECKDB statement.  This is a well named argument because this <span style="color: #ff0000;"><strong>can/will cause rows in your table(s) to be removed</strong> </span>in order to attempt to fix the corruption.  Always be sure to do a full backup BEFORE using the REPAIR_ALLOW_DATA_LOSS option just to be sure you can get back to where you are now if something goes wrong.  This option also doesn&#8217;t care about constraints so be sure to run a DBCC CHECKCONSTRAINTS command after the REPAIR_ALLOW_DATA_LOSS.</p>
<p>Anyways at the end of the day corruption happens&#8230; do what you can through alerts and scheduled running of DBCC CHECKDB to try and capture/isolate the corruption as soon as possible in order to minimize damage and impact to the business. </p>
<p>One final thought&#8230; even though you may think that you fixed the problem(s) ALWAYS run a final CHECKDB just to make sure that you&#8217;ve really saved the world (or at least your database) from corruption.</p>
<p>Here is the Microsoft Books Online for <a href="http://msdn.microsoft.com/en-us/library/ms176064.aspx" target="_blank">DBCC CHECKDB</a> make sure to give this a read (twice) before acting.</p>
<p>Enjoy!!</p>
<p><span><a href="http://benchmarkitconsulting.com" target="_blank"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" width="157" height="74" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" width="120" height="60" /> </a></span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Corrupt+as+a+Dirty+Politican%26%238230%3B+breathe+and+think+before+acting.+http://tinyurl.com/ct9klq" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/&amp;title=Corrupt+as+a+Dirty+Politican%26%238230%3B+breathe+and+think+before+acting." title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/&amp;title=Corrupt+as+a+Dirty+Politican%26%238230%3B+breathe+and+think+before+acting." title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/&amp;title=Corrupt+as+a+Dirty+Politican%26%238230%3B+breathe+and+think+before+acting." title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/04/16/corrupt-as-a-dirty-politican-breathe-and-think-before-acting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistics&#8230; Peeling Away More Of The Onion</title>
		<link>http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/</link>
		<comments>http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 16:10:12 +0000</pubDate>
		<dc:creator>Colin Stasiuk</dc:creator>
				<category><![CDATA[Benchmark IT Consulting]]></category>
		<category><![CDATA[Colin Stasiuk]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sp_updatestats]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://benchmarkitconsulting.com/?p=453</guid>
		<description><![CDATA[So this post is a continuation of sorts of my last post on Updating Statistics before or after an index rebuild. I asked myself the question &#8220;How often should you run statistic maintenance in general? and do I have to run any statistic maintenance if I have auto update stats enabled?&#8221; OK I didn&#8217;t REALLY [...]]]></description>
			<content:encoded><![CDATA[<p>So this post is a continuation of sorts of <a href="http://benchmarkitconsulting.com/colin-stasiuk/2009/02/11/update-statistics-before-or-after-an-index-rebuild/" target="_blank">my last post </a> on Updating Statistics before or after an index rebuild.  I asked myself the question &#8220;How often should you run statistic maintenance in general? and do I have to run any statistic maintenance if I have auto update stats enabled?&#8221;  OK I didn&#8217;t REALLY ask myself the question but I thought it would be an interesting blog post LOL.  The general concensus out there seems to be something like this:  If 20% of my data has changes auto update stats will update my statistics. (Some quotes on the topic below)</p>
<p>&#8220;SQL server starts Auto update stats when data modification for a table is more than 20 %. &#8221;</p>
<p>&#8220;Statistics will only be updated by Auto Update when SQL Server thinks it needs to be done (which is typically when 20% of the rows have changed). If you are manually updating statistics pretty frequently, AutoUpdate may not fire very often, if at all.&#8221;</p>
<p>&#8220;However, you might not know that approximately 20% of a table needs to change before triggering an auto_update statistics run for the given table.  If the table is really big, it’s possible that you’re simply not changing enough data.&#8221;</p>
<p>&#8220;It will be nice if we can change the 500+20% formula so we can have the auto update stats more often / less often&#8221;</p>
<p>So I thought why not put that to the test and see what is happening.  Let&#8217;s first make sure that auto update statistics is enabled on our working database:</p>
<p><code style="font-size: 12px;"><span style="color:blue">SELECT </span><span style="color:magenta">DATABASEPROPERTY</span><span style="color:gray">(</span><span style="color:magenta">DB_NAME</span><span style="color:gray">(), </span><span style="color:red">&#39;IsAutoUpdateStatistics&#39;</span><span style="color:gray">) </span><span style="color:blue">AS </span><span style="color:red">&#39;IsAutoUpdateStatisticsEnabled&#39;<br /></span></code></p>
<p>Make sure this value is set to 1 otherwise this test wont really mean much to you.</p>
<p>Now let&#8217;s set ourselves up a table to work with:</p>
<p><code style="font-size: 12px;"><span style="color:blue">SET&nbsp;</span><span style="color:black">NOCOUNT&nbsp;</span><span style="color:blue">ON&nbsp; </p>
<p>DECLARE&nbsp;</span><span style="color:#434343">@RowID&nbsp;</span><span style="color:blue">INT&nbsp; <br />SET&nbsp;</span><span style="color:#434343">@RowID&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:black">0&nbsp; </p>
<p></span><span style="color:blue">CREATE&nbsp;TABLE&nbsp;</span><span style="color:black">tblSQLServerPediaUsers</span><span style="color:gray">(&nbsp; <br />&nbsp;&nbsp;</span><span style="color:black">ID&nbsp;</span><span style="color:blue">INT</span><span style="color:gray">,&nbsp; <br />&nbsp;&nbsp;</span><span style="color:black">FirstName&nbsp;</span><span style="color:blue">NVARCHAR</span><span style="color:gray">(</span><span style="color:black">50</span><span style="color:gray">), <br />&nbsp;&nbsp;</span><span style="color:black">LastName&nbsp;</span><span style="color:blue">NVARCHAR</span><span style="color:gray">(</span><span style="color:black">50</span><span style="color:gray">), <br />&nbsp;&nbsp;</span><span style="color:black">Address1&nbsp;</span><span style="color:blue">NVARCHAR</span><span style="color:gray">(</span><span style="color:black">50</span><span style="color:gray">), <br />&nbsp;&nbsp;</span><span style="color:black">City&nbsp;</span><span style="color:blue">NVARCHAR</span><span style="color:gray">(</span><span style="color:black">50</span><span style="color:gray">) <br />&nbsp;&nbsp;</span><span style="color:blue">CONSTRAINT&nbsp;</span><span style="color:black">PK_tblSQLServerPediaUsers&nbsp;</span><span style="color:blue">PRIMARY&nbsp;KEY&nbsp;CLUSTERED&nbsp;</span><span style="color:gray">(</span><span style="color:black">ID</span><span style="color:gray">))&nbsp; </p>
<p></span><span style="color:blue">WHILE&nbsp;</span><span style="color:#434343">@RowID&nbsp;</span><span style="color:gray">&lt;&gt;&nbsp;</span><span style="color:black">10000&nbsp; <br />&nbsp;&nbsp;</span><span style="color:blue">BEGIN&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SET&nbsp;</span><span style="color:#434343">@RowID&nbsp;</span><span style="color:blue">=&nbsp;</span><span style="color:#434343">@RowID&nbsp;</span><span style="color:gray">+&nbsp;</span><span style="color:black">1&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:blue">INSERT&nbsp;INTO&nbsp;</span><span style="color:black">tblSQLServerPediaUsers</span><span style="color:gray">(</span><span style="color:black">ID</span><span style="color:gray">,&nbsp;</span><span style="color:black">FirstName</span><span style="color:gray">,&nbsp;</span><span style="color:black">LastName</span><span style="color:gray">,&nbsp;</span><span style="color:black">Address1</span><span style="color:gray">,</span><span style="color:black">City</span><span style="color:gray">)&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:blue">SELECT&nbsp;</span><span style="color:#434343">@RowID</span><span style="color:gray">,&nbsp;</span><span style="color:red">&#39;John&#39;&nbsp;</span><span style="color:gray">,&nbsp;</span><span style="color:red">&#39;Smith&#39;</span><span style="color:gray">,&nbsp;</span><span style="color:red">&#39;123&nbsp;SQLServerPedia&nbsp;Way&#39;</span><span style="color:gray">,&nbsp;</span><br />
<span style="color:red">&#39;NHL&nbsp;City&#39; <br />&nbsp;&nbsp;</span><span style="color:blue">END </p>
<p>CREATE&nbsp;INDEX&nbsp;</span><span style="color:black">IX_City&nbsp;</span><span style="color:blue">ON&nbsp;</span><span style="color:black">tblSQLServerPediaUsers</span><span style="color:gray">(</span><span style="color:black">City</span><span style="color:gray">)</span></code></p>
<p>And just for tracking purposes let&#8217;s see what our statistics look like:</p>
<p><code style="font-size: 12px;"><span style="color:blue">DBCC </span><span style="color:black">SHOW_STATISTICS </span><span style="color:gray">(</span><span style="color:red">&#39;tblSQLServerPediaUsers&#39;</span><span style="color:gray">, </span><span style="color:black">PK_tblSQLServerPediaUsers</span><span style="color:gray">) </span><span style="color:blue">WITH </span><span style="color:black">STAT_HEADER<br /></span><span style="color:blue">DBCC </span><span style="color:black">SHOW_STATISTICS </span><span style="color:gray">(</span><span style="color:red">&#39;tblSQLServerPediaUsers&#39;</span><span style="color:gray">, </span><span style="color:black">IX_City</span><span style="color:gray">) </span><span style="color:blue">WITH </span><span style="color:black">STAT_HEADER</span></code></p>
<p>OK so no statistics for our Primary Key (Clustered Index) and up to date statistics with a full scan for our non clustered index.  OK so taking what seems to be general public acceptance that if you change 20% or more of the table data that auto update statistics should kick off let&#8217;s start a profiler trace and in your events selection under Performance let&#8217;s check off Auto Stats.  This will tell us if/when auto stats gets executed.  So let&#8217;s update more than 20% of the data in the table (while the profiler trace is running):</p>
<p><code style="font-size: 12px;"><span style="color:blue">UPDATE </span><span style="color:black">tblSQLServerPediaUsers<br /></span><span style="color:blue">SET&nbsp;&nbsp;&nbsp;&nbsp;</span><br />
<span style="color:black">City </span><span style="color:blue">= </span><span style="color:red">&#39;Edmonton&#39;</span><span style="color:gray">, <br />&nbsp;&nbsp; </span><span style="color:black">FirstName </span><span style="color:blue">= </span><span style="color:red">&#39;Ales&#39;</span><span style="color:gray">,<br />&nbsp;&nbsp; </span><span style="color:black">LastName </span><span style="color:blue">= </span><span style="color:red">&#39;Hemsky&#39;</span><span style="color:gray">,<br />&nbsp;&nbsp; </span><span style="color:black">Address1 </span><span style="color:blue">= </span><span style="color:red">&#39;Rexall Place&#39;<br /></span><span style="color:blue">WHERE </span><span style="color:black">ID </span><span style="color:blue">IN</span><span style="color:gray">( </span><span style="color:blue">SELECT TOP </span><span style="color:black">2499 ID<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">FROM </span><span style="color:black">tblSQLServerPediaUsers<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color:blue">ORDER BY </span><span style="color:magenta">NEWID</span><span style="color:gray">())</span></code></p>
<p>And if we look at the profiler trace we see Auto Stats ran but if we look at the TextData we see:</p>
<p>Updated: tblSQLServerPediaUsers.PK_tblSQLServerPediaUsers</p>
<p>Hmmmm the index IX_City didn&#8217;t appear to get updated.  I updated more than 20% of the table and auto stats did happen but it only happened for my Primary Key. Let&#8217;s check our statistics just to be sure:</p>
<p><code style="font-size: 12px;"><span style="color:blue">DBCC </span><span style="color:black">SHOW_STATISTICS </span><span style="color:gray">(</span><span style="color:red">&#39;tblSQLServerPediaUsers&#39;</span><span style="color:gray">, </span><span style="color:black">PK_tblSQLServerPediaUsers</span><span style="color:gray">) </span><span style="color:blue">WITH </span><span style="color:black">STAT_HEADER<br /></span><span style="color:blue">DBCC </span><span style="color:black">SHOW_STATISTICS </span><span style="color:gray">(</span><span style="color:red">&#39;tblSQLServerPediaUsers&#39;</span><span style="color:gray">, </span><span style="color:black">IX_City</span><span style="color:gray">) </span><span style="color:blue">WITH </span><span style="color:black">STAT_HEADER</span></code></p>
<p>We see the Primary Key now has statistics (as expected) and we also confirmed that the IX_City did not get updated.  Let&#8217;s see how this affects querying the tblSQLServerPediaUsers table (make sure to have &#8220;show execution plan&#8221; turned on as well):</p>
<p><code style="font-size: 12px;"><span style="color:blue">SET STATISTICS </span><span style="color:black">IO </span><span style="color:blue">ON<br /></span><span style="color:black">GO<br /></span><span style="color:blue">SELECT </span><span style="color:black">FirstName</span><span style="color:gray">, </span><span style="color:black">LastName </span><span style="color:blue">FROM </span><span style="color:black">tblSQLServerPediaUsers </span><span style="color:blue">WHERE </span><span style="color:black">City </span><span style="color:blue">= </span><span style="color:red">&#39;Edmonton&#39;</span></code></p>
<p>Execution Plan shows that our index (IX_City) is used and the Logical Reads is at 5011.  So I guess all is right in the world right?  Just for fun let&#8217;s see what kind of stats we would get if we forced the same query to use the primary key (clustered index)</p>
<p><code style="font-size: 12px;"><span style="color:blue">SET STATISTICS </span><span style="color:black">IO </span><span style="color:blue">ON<br /></span><span style="color:black">GO<br /></span><span style="color:blue">SELECT </span><span style="color:black">FirstName</span><span style="color:gray">, </span><span style="color:black">LastName </span><span style="color:blue">FROM </span><span style="color:black">tblSQLServerPediaUsers </span><span style="color:blue">WITH</span><span style="color:gray">(</span><span style="color:blue">INDEX=</span><span style="color:black">PK_tblSQLServerPediaUsers</span><span style="color:gray">) </span><span style="color:blue">WHERE </span><span style="color:black">City </span><span style="color:blue">= </span><span style="color:red">&#39;Edmonton&#39;</span></code></p>
<p>Execution Plan shows that our forcing the query to use the Primary Key (PK_tblSQLServerPediaUsers) worked but wait a sec&#8230; the logical reads is at 127.  In our previous run why didn&#8217;t the query engine use the primary key instead.  Let&#8217;s look at what the profiler trace has in it:</p>
<p>Using the IX_City Index:<br />
CPU		47<br />
READS		5011<br />
WRITES		0<br />
DURATION	61</p>
<p>Forcing the query to use PK_tblSQLServerPediaUsers Clustered Index:<br />
CPU		15<br />
READS		127<br />
WRITES		0<br />
DURATION	43</p>
<p>CPU is lower, reads is lower, and duration is lower.  So why didn&#8217;t the query engine use PK_tblSQLServerPediaUsers instead of IX_city?  This is because the auto update stats did not update ALL the statistics. Let&#8217;s run an sp_updatestats:</p>
<p><code style="font-size: 12px;"><span style="color:blue">EXEC </span><span style="color:darkred">sp_updatestats</span></code></p>
<p>Now let&#8217;s run the original query again (without forcing the query to use the primary key):</p>
<p><code style="font-size: 12px;"><span style="color:blue">SET STATISTICS </span><span style="color:black">IO </span><span style="color:blue">ON<br /></span><span style="color:black">GO<br /></span><span style="color:blue">SELECT </span><span style="color:black">FirstName</span><span style="color:gray">, </span><span style="color:black">LastName </span><span style="color:blue">FROM </span><span style="color:black">tblSQLServerPediaUsers </span><span style="color:blue">WHERE </span><span style="color:black">City </span><span style="color:blue">= </span><span style="color:red">&#39;Edmonton&#39;</span></code></p>
<p>Look at that&#8230; the query now uses the primary key instead of using the IX_City index.</p>
<p>So back to our original question of &#8220;Do I have to update my statistics if I have auto update stats enabled&#8221; My answer stays the same (yes) but now I have a working example to argue my point of view with.  </p>
<p>Disclaimer (lol):  I&#8217;m the first to admit that I don&#8217;t know absolutely everything there is to know about the query engine so please feel free to comment and provide some further information/details that I might be leaving out, missing, or TOTALLY wrong about.</p>
<p>Enjoy!!</p>
<p><a href="http://benchmarkitconsulting.com"><img class="alignnone size-full wp-image-402" title="benchmark_sm" src="http://benchmarkitconsulting.com/wp-content/uploads/2009/02/benchmark_sm.jpg" alt="" /></a><a href="http://sqlserverpedia.com/wiki/Editors#Colin_Stasiuk" target="_blank"><img src="http://sqlserverpedia.com/badges/SQLServerPedia_Badge_Blogger.jpg" alt="" /> </a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Statistics%26%238230%3B+Peeling+Away+More+Of+The+Onion+http://tinyurl.com/b86by7" title="Post to Twitter"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-twitter-big4.png" alt="Post to Twitter" /></a> <a class="tt" href="http://delicious.com/post?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/&amp;title=Statistics%26%238230%3B+Peeling+Away+More+Of+The+Onion" title="Post to Delicious"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-delicious-big4.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/&amp;title=Statistics%26%238230%3B+Peeling+Away+More+Of+The+Onion" title="Post to Digg"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-digg-big4.png" alt="Post to Digg" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/&amp;title=Statistics%26%238230%3B+Peeling+Away+More+Of+The+Onion" title="Post to StumbleUpon"><img class="nothumb" src="http://benchmarkitconsulting.com/wp-content/plugins/tweet-this/icons/tt-su-big4.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://benchmarkitconsulting.com/colin-stasiuk/2009/02/17/statistics-peeling-away-more-of-the-onion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

