<?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>youdidwhatwithtsql.com</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Mon, 01 Mar 2010 21:32:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Run a Stored Procedure when SQL Server starts</title>
		<link>http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693</link>
		<comments>http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:08:18 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693</guid>
		<description><![CDATA[Recently I needed to setup a SQL Server box so it had access to a mapped drive to support a legacy application. I created the below stored procedure, which utilises the subst command. to get this done.

?View Code TSQLCREATE PROCEDURE usp_mapDDrive
AS
BEGIN
	EXEC master.dbo.xp_cmdshell 'Subst d: c:\', no_output;
END
GO

I needed a way of ensuring this mapped drive was [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693">Run a Stored Procedure when SQL Server starts</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to setup a <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> box so it had access to a mapped drive to support a legacy application. I created the below stored procedure, which utilises the <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx?mfr=true" target="_blank">subst</a> command. to get this done.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p693code4'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6934"><td class="code" id="p693code4"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> usp_mapDDrive
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">xp_cmdshell</span> <span style="color: #FF0000;">'Subst d: c:<span style="color: #000099; font-weight: bold;">\'</span>, no_output;
END
GO</span></pre></td></tr></table></div>

<p>I needed a way of ensuring this mapped drive was always available to SQL Server. After considering various ways of doing this I settled with <a href="http://msdn.microsoft.com/en-us/library/ms181720.aspx" target="_blank">sp_procoption</a>. This is a neat little system stored procedure that you can use to execute a user proc at startup. Setting this up is easy.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p693code5'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6935"><td class="code" id="p693code5"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">exec</span> <span style="color: #AF0000;">sp_procoption</span> @ProcName <span style="color: #808080;">=</span> usp_mapDDrive,
     @OptionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'STARTUP'</span>,
     @OptionValue <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ON'</span>;</pre></td></tr></table></div>

<p>Turning it off again is simple.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p693code6'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6936"><td class="code" id="p693code6"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">exec</span> <span style="color: #AF0000;">sp_procoption</span> @ProcName <span style="color: #808080;">=</span> usp_mapDDrive,
     @OptionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'STARTUP'</span>,
     @OptionValue <span style="color: #808080;">=</span> <span style="color: #FF0000;">'OFF'</span>;</pre></td></tr></table></div>

<p>Two caveats; you must create your stored procedure in the <a href="http://msdn.microsoft.com/en-us/library/ms187837.aspx" target="_blank">master database</a> and it cannot contain input or output parameters. </p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693">Run a Stored Procedure when SQL Server starts</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/run-a-stored-procedure-when-sql-server-starts/693/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get TFL Tube data with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689</link>
		<comments>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:18:24 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[data.gov.uk]]></category>
		<category><![CDATA[London Datastore]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689</guid>
		<description><![CDATA[The London Datastore has loads of datasets available that we can use for free. One of the datasets available is a list of TFL Station Locations. The station location feed is a geo-coded KML feed of most of London Underground, DLR and London Overground stations. Here&#8217;s Powershell script that will extract this data from a [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689">Get TFL Tube data with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://data.london.gov.uk/" target="_blank">London Datastore</a> has loads of datasets available that we can use for free. One of the datasets available is a list of <a href="http://data.london.gov.uk/datastore/package/tfl-station-locations" target="_blank">TFL Station Locations</a>. The station location feed is a geo-coded KML feed of most of London Underground, DLR and London Overground stations. Here&#8217;s <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> script that will extract this data from a url and write it to a pipe-delimited file ready for import into the database of your choice. </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p689code8'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6898"><td class="code" id="p689code8"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$xml</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> XML
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://www.tfl.gov.uk/tfl/syndication/feeds/stations.kml&quot;</span>
<span style="color: #800080;">$csvFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$env:UserProfile\Desktop\tfl_tubes.csv&quot;</span>;
&nbsp;
<span style="color: #008000;"># Empty file if it already exists</span>
<span style="color: #008080; font-weight: bold;">Set-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800080;">$null</span>;
<span style="color: #008000;"># Add headers to file</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800000;">&quot;Station|Address|Coordinates&quot;</span>;
&nbsp;
<span style="color: #008000;"># Load the xml</span>
<span style="color: #800080;">$xml</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$url</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$stations</span> <span style="color: pink;">=</span> <span style="color: #800080;">$xml</span>.kml.Document.Placemark;
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$station</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$stations</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.name;
	<span style="color: #800080;">$description</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.description;
	<span style="color: #800080;">$coordinates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.Point.coordinates
	<span style="color: #008000;"># This data needs cleaning a bit</span>
	<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$name</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$description</span> <span style="color: pink;">=</span> <span style="color: #800080;">$description</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$coordinates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$coordinates</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># Ad line to the csv file</span>
	<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800000;">&quot;$name|$description|$coordinates&quot;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>After running the script check your desktop for a file called <strong>tfl_tubes.csv</strong> which should look something like below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/tfl_tubes.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TFL Station Locations csv data file" border="0" alt="TFL Station Locations csv data file" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/tfl_tubes_thumb.png" width="244" height="183" /></a></p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689">Get TFL Tube data with Powershell</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free Database Sync Tools</title>
		<link>http://www.youdidwhatwithtsql.com/free-database-sync-tools/684</link>
		<comments>http://www.youdidwhatwithtsql.com/free-database-sync-tools/684#comments</comments>
		<pubDate>Wed, 24 Feb 2010 21:45:55 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Database Synchronisation]]></category>
		<category><![CDATA[SQL Compare]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/free-database-sync-tools/684</guid>
		<description><![CDATA[I&#8217;m a big fan of Redgate SQL Compare but it&#8217;s been good to see the arrival of a few free alternatives. Life previous to these tools really does seem like the stone age now eliminating those &#34;oh $h**, I forgot about that!&#34; moments. I&#8217;d always go for Redgate every time but, if you don&#8217;t have [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/free-database-sync-tools/684">Free Database Sync Tools</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of <a href="http://www.red-gate.com/products/SQL_Compare/index-2.htm" target="_blank">Redgate SQL Compare</a> but it&#8217;s been good to see the arrival of a few free alternatives. Life previous to these tools really does seem like the stone age now eliminating those <em>&quot;oh $h**, I forgot about that!&quot;</em> moments. I&#8217;d always go for Redgate every time but, if you don&#8217;t have it in your budget, these tools may be worth checking out.</p>
<p><a href="http://www.codeplex.com/OpenDBiff/" target="_blank">OpenDBDiff</a></p>
<p>This is an open source project hosted on <a href="http://www.codeplex.com" target="_blank">Codeplex</a> that has database compare and, crucially, synchronisation abilities. I&#8217;ve used this tool in a few production deployments and have found it useful. I don&#8217;t fully trust it yet, it took a while to trust Redgate, but I haven&#8217;t encountered any major difficulties yet. I&#8217;ve had issues with synchronisation scripts and dependency ordering but nothing I have found too frustrating.</p>
<p>The user interface is basic, but well designed, and it&#8217;s easy to get productive straight away.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/OpenDBDiff_1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OpenDBDiff Main Screen" border="0" alt="OpenDBDiff Main Screen" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/OpenDBDiff_1_thumb.png" width="244" height="150" /></a> </p>
<p>You can&#8217;t stay within the tool to synchronise your databases but, as there is a non-functional &quot;Actions Report&quot; tab, it seems this is on the roadmap.</p>
<p>Open DBDiff can synchronize the following object types.</p>
<ul>
<li>Tables (including Table Options like vardecimal, text in row, etc.) </li>
<li>Columns (including Computed Columns, XML options, Identities, etc.) </li>
<li>Constraints </li>
<li>Indexes (and XML Indexes) </li>
<li>XML Schemas </li>
<li>Table Types </li>
<li>User Data Types (UDT) </li>
<li>CLR Objects (Assemblies, CLR-UDT, CLR-Stored Procedure, CLR-Triggers) </li>
<li>Triggers (including DDL Triggers) </li>
<li>Synonyms </li>
<li>Schemas </li>
<li>File groups </li>
<li>Views </li>
<li>Functions </li>
<li>Store Procedures </li>
<li>Partition Functions/Schemes </li>
<li>Users </li>
<li>Roles</li>
</ul>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/OpenDBDiff_Syncronisation_Script.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="OpenDBDiff Syncronisation Script" border="0" alt="OpenDBDiff Syncronisation Script" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/OpenDBDiff_Syncronisation_Script_thumb.png" width="244" height="150" /></a> </p>
<p>I did have trouble connecting to different instances of SQL Server on the same machine. This shouldn&#8217;t matter much for production use as we&#8217;d normally be synchronising different boxes.</p>
<p><a href="http://www.starinix.com/sqlcompare02.htm" target="_blank">Starinix Database Compare</a></p>
<p>This is a freeware tool that is able to compare <a href="http://www.mysql.com" target="_blank">MySQL</a>, Access and <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> databases and any combinations thereof. Not sure this would be useful in my case but I guess someone might do (I can already tell you your MySQL and SQL Server procedures do not match!).</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starnix_Database_Compare.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Starinix Database Compare" border="0" alt="Starinix Database Compare" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starnix_Database_Compare_thumb.png" width="244" height="150" /></a> </p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starinix_Database_Compare_1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Starinix Database Compare" border="0" alt="Starinix Database Compare" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starinix_Database_Compare_1_thumb.png" width="244" height="150" /></a> </p>
<p><strong>Key features</strong></p>
<ul>
<li>Take snapshots of the structure of the database and review it later. </li>
<li>Snapshots can be saved anywhere, allowing you to take snapshots of any database for reviewing later. </li>
<li>Compare two online database connections. </li>
<li>Compare an online database connection to an off-line snapshot. </li>
<li>Compare two off-line snapshots. </li>
<li>Use integrated or user based security. </li>
<li>Compares: views, constraints, stored procedures, functions, tables and fields. </li>
<li>Compare Access database to an SQL Server database. </li>
<li>Compare Access database to a MySQL database. </li>
<li>Compare Access database to another Access database. </li>
<li>Compare MySQL Database to an SQL Server Database. </li>
<li>Compare SQL Server 2000 to SQL Server 2005.</li>
</ul>
<p>I&#8217;ve done some quick testing of this tool and it does seem to be accurate, spotting all of my edits made to tables, procedures and functions. The interface is ok but does need some polish. For example, it would be a nice touch for the &quot;SQL View&quot; scroll bar to scroll both the source and destination views. Identifying differences to large procedures isn&#8217;t as easy as it should be but clicking &quot;Script Comparison&quot; launches an external diff tool that does a better job.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starnix_Procedure_Compare.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Starinix Procedure Compare" border="0" alt="Starinix Procedure Compare" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/Starnix_Procedure_Compare_thumb.png" width="244" height="148" /></a> </p>
<p>This is strictly a compare tool, meaning there are no synchronisation abilities, so you&#8217;ll have to do a little leg work to implement any needed changes.</p>
</p>
</p>
</p>
<p>Overall there&#8217;s no clear winner for me out of these two free tools. Both products have easy to use GUIs. <a href="http://opendbiff.codeplex.com/" target="_blank">OpenDBDiff</a> clearly has the edge as a synchronisation tool but <a href="http://starinix.com/sqlcompare02.htm" target="_blank">Starinix</a> has a few nice touches like the external diff tool and the snapshot feature.</p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/free-database-sync-tools/684">Free Database Sync Tools</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/free-database-sync-tools/684/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Console input with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/console-input-with-powershell/673</link>
		<comments>http://www.youdidwhatwithtsql.com/console-input-with-powershell/673#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:51:07 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell Scripting]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/console-input-with-powershell/673</guid>
		<description><![CDATA[I&#8217;m looking at building some Powershell scripts that can accept user input to perform different tasks with a wizard style interface. As it happens this is fairly easily achieved with the Read-Host cmdlet. Here&#8217;s a quick script showing how such a powershell script may look.

?View Code POWERSHELLfunction mainMenu&#40;&#41;
&#123;
	Clear-Host;
	Write-Host &#34;============&#34;;
	Write-Host &#34;= MAINMENU =&#34;;
	Write-Host &#34;============&#34;;
	Write-Host &#34;1. Press [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/console-input-with-powershell/673">Console input with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking at building some <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> scripts that can accept user input to perform different tasks with a wizard style interface. As it happens this is fairly easily achieved with the <a href="http://technet.microsoft.com/en-us/library/ee176935.aspx" target="_blank">Read-Host</a> cmdlet. Here&#8217;s a quick script showing how such a <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">powershell</a> script may look.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p673code10'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p67310"><td class="code" id="p673code10"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> mainMenu<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Clear<span style="color: pink;">-</span>Host;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;============&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;= MAINMENU =&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;============&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;1. Press '1' for this option&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;2. Press '2' for this option&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;3. Press '3' for this option&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;4. Press '4' for this option&quot;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">function</span> returnMenu<span style="color: #000000;">&#40;</span><span style="color: #800080;">$option</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	Clear<span style="color: pink;">-</span>Host;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;You chose option $option&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Press any key to return to the main menu.&quot;</span>;
	<span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">do</span>
<span style="color: #000000;">&#123;</span>
	mainMenu;
	<span style="color: #800080;">$input</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Enter a number for an option or type <span style="color: #008080; font-weight: bold;">`&quot;</span>quit<span style="color: #008080; font-weight: bold;">`&quot;</span> to finish.&quot;</span>
	<span style="color: #0000FF;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$input</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800000;">&quot;1&quot;</span>
		<span style="color: #000000;">&#123;</span>
			returnMenu <span style="color: #800080;">$input</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800000;">&quot;2&quot;</span>
		<span style="color: #000000;">&#123;</span>
			returnMenu <span style="color: #800080;">$input</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800000;">&quot;3&quot;</span>
		<span style="color: #000000;">&#123;</span>
			returnMenu <span style="color: #800080;">$input</span>;		
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800000;">&quot;4&quot;</span>
		<span style="color: #000000;">&#123;</span>
			returnMenu <span style="color: #800080;">$input</span>;		
		<span style="color: #000000;">&#125;</span>
		<span style="color: #800000;">&quot;quit&quot;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008000;"># nothing</span>
		<span style="color: #000000;">&#125;</span>
		default
		<span style="color: #000000;">&#123;</span>
			Clear<span style="color: pink;">-</span>Host;
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Invalid input. Please enter a valid option. Press any key to continue.&quot;</span>;
			<span style="color: #800080;">$host</span>.UI.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">until</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$input</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;quit&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
Clear<span style="color: pink;">-</span>Host;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/powershell_console_input_menu.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="powershell console input menu" border="0" alt="powershell console input menu" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/powershell_console_input_menu_thumb.png" width="644" height="350" /></a> </p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/powershell_console_input_menu_1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="powershell console input menu 1" border="0" alt="powershell console input menu 1" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/powershell_console_input_menu_1_thumb.png" width="644" height="350" /></a></p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/console-input-with-powershell/673">Console input with Powershell</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/console-input-with-powershell/673/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS: Make your output files dynamic part 2</title>
		<link>http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664</link>
		<comments>http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664#comments</comments>
		<pubDate>Sat, 20 Feb 2010 19:55:10 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664</guid>
		<description><![CDATA[A few weeks ago I blogged about my attempts to make dynamic output files in ssis. The idea here was to make an ssis package, producing a text file output, that would cope with complete changes to the data source. If you wanted to add a column all you needed to do was change the [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664">SSIS: Make your output files dynamic part 2</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I blogged about my attempts to make <a href="http://www.youdidwhatwithtsql.com/ssis-make-your-output-files-dynamic/616" target="_blank">dynamic output files in ssis</a>. The idea here was to make an <a href="http://www.microsoft.com/sqlserver/2005/en/us/integration-services.aspx" target="_blank">ssis</a> package, producing a text file output, that would cope with complete changes to the data source. If you wanted to add a column all you needed to do was change the stored procedure definition that the data was derived from. While this was functional it did have a couple of issues.</p>
<ul>
<li>The Script Task seems to buckle for XML data types giving an unsupported conversion error. (Use the Person.Contact table in the AdventureWorks database to view this issue). </li>
<li>The package does not seem to cope with a large number of rows. Execution appears to freeze for datasets containing somewhat over 1,000 rows. (Use the Person.Address table in the AdventureWorks database to view this issue). I’m wondering if this is due to size limitation with the System.Object type. </li>
</ul>
<p>Here&#8217;s quick run through of how I resolved the issues. The basic idea was to do all of the data access in VB.Net rather than using an <a href="http://technet.microsoft.com/en-us/library/ms141003.aspx" target="_blank">Execute SQL Task</a> to store a resultset in a System.Object variable.</p>
<p>Open <a href="http://msdn.microsoft.com/en-us/library/ms173767.aspx" target="_blank">BIDS</a> and create a new Integration Services Project.</p>
<p>First add a string variable to the project as illustrated below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_filename_variable.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssis filename variable" border="0" alt="ssis filename variable" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_filename_variable_thumb.png" width="644" height="156" /></a> </p>
<p>Set the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.variable.evaluateasexpression.aspx" target="_blank">EvaluateAsExpression</a> property to true and enter the following expression.</p>
<pre> (DT_WSTR,4)YEAR(GETDATE()) + "_"
    + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + "_"
    + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2) + "_"
    + RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2) + "_" + RIGHT("0" + (DT_WSTR,2)DATEPART("mi", GETDATE()), 2) + "_" + RIGHT("0" + (DT_WSTR,2)DATEPART("ss", GETDATE()), 2) + ".txt"</pre>
<p>This will provide us with a datetime stamped filename looking similar to <strong>2010_02_20_15_40_36.txt</strong>.</p>
<p>Next add another string variable called <strong>query</strong> and enter a statement to execute a stored procedure that returns a resultset. Any one will do as the package should be agnostic to the results. </p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_query_variable.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssis query variable" border="0" alt="ssis query variable" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_query_variable_thumb.png" width="644" height="159" /></a> </p>
<p>I&#8217;m using the below stored procedure running against the <a href="http://msdn.microsoft.com/en-us/library/ms124501.aspx" target="_blank">AdventureWorks</a> sample database.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p664code13'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66413"><td class="code" id="p664code13"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>AdventureWorks<span style="color: #808080;">&#93;</span>
GO
<span style="color: #008080;">/****** Object:  StoredProcedure [dbo].[usp_test]    Script Date: 02/20/2010 15:48:49 ******/</span>
<span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
GO
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>
GO
<span style="color: #008080;">-- =============================================</span>
<span style="color: #008080;">-- Author:		Rhys Campbell</span>
<span style="color: #008080;">-- Create date: 2010-02-20</span>
<span style="color: #008080;">-- Description:	Test proc</span>
<span style="color: #008080;">-- =============================================</span>
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>usp_test<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #008080;">-- SET NOCOUNT ON added to prevent extra result sets from</span>
	<span style="color: #008080;">-- interfering with SELECT statements.</span>
	<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>;
&nbsp;
    	<span style="color: #008080;">-- Insert statements for procedure here</span>
	<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
	<span style="color: #0000FF;">FROM</span> Person.<span style="color: #202020;">Contact</span>;
&nbsp;
<span style="color: #0000FF;">END</span></pre></td></tr></table></div>

<p>Next add an <a href="http://msdn.microsoft.com/en-us/library/ms141676.aspx" target="_blank">ADO.NET Connection Manager</a> to the project pointing this at the database containing your stored procedure. Rename the connection manager to <strong>DBConnection</strong> as we will be referencing this by name in code later.</p>
<p>Drop a Script Task onto the designer and edit its properties. Add the <strong>filename</strong> and <strong>query </strong>variables to the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.pipeline.scriptcomponent.readonlyvariables.aspx" target="_blank">ReadOnlyVariables</a> property. </p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_script_task_properties.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssis script_task properties" border="0" alt="ssis script_task properties" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_script_task_properties_thumb.png" width="570" height="484" /></a> </p>
<p>Set the script language to <strong>Microsoft Visual Basic 2008</strong> and then click &quot;Edit Script&quot;. Paste the below code into the editor.</p>
<pre lang="VB.NET">
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
	Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

	Enum ScriptResults
		Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
		Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
	End Enum

    Public Sub Main()

        ' Get the datetime stamped filename
        Dim filename As String = Dts.Variables("filename").Value.ToString
        ' Get the user desktop directory. We'll write the output file to here
        ' You probably want to use some other location for production purposes
        Dim userProfileDir As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory).ToString

        ' Get the Connection string. Must be called "DBConnection"
        Dim connStr As String = Me.Dts.Connections.Item("DBConnection").ConnectionString.ToString

        ' Get the query set in the ssis variables
        Dim query As String = Dts.Variables("query").Value.ToString

        ' Setup DB access stuff
        Dim con As SqlClient.SqlConnection = New SqlClient.SqlConnection(connStr)
        Dim comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(query, con)
        Dim reader As SqlClient.SqlDataReader

        ' Open the connection
        con.Open()

        ' Get results
        reader = comm.ExecuteReader()

        ' temp variable to hold lines
        Dim line As String = ""

        ' Get the column names from the resultset
        For index As Integer = 0 To (reader.FieldCount - 1)
            line &#038;= reader.GetName(index) &#038; "|"
        Next

        ' remove last pipe
        line = line.Substring(0, line.Length - 1)

        ' write the column headers to the text file
        appendToTextFile(userProfileDir &#038; "\" &#038; filename, line)

        ' Write each row in the resultset to the text file
        While reader.Read()

            line = ""
            ' Add each column value to line
            For index As Integer = 0 To (reader.FieldCount - 1)
                ' Removing any pipes and newline to avoid screwing up our file
                line &#038;= reader.GetValue(index).ToString.Replace("|", "").Replace(ControlChars.CrLf, vbNullString) &#038; "|"
            Next

            ' remove last pipe and add a new line
            line = line.Substring(0, line.Length - 1)

            ' write the line to the output file
            appendToTextFile(userProfileDir &#038; "\" &#038; filename, line)

        End While

        ' clean up
        con.Close()
        comm = Nothing
        reader = Nothing
        con = Nothing

        Dts.TaskResult = ScriptResults.Success

    End Sub
    Public Sub appendToTextFile(ByVal file As String, ByVal line As String)

        ' Create a writer object that appends to a text file if it exists
        Dim objWriter As New System.IO.StreamWriter(file, True)
        objWriter.WriteLine(line)
        objWriter.Close()
        objWriter = Nothing

    End Sub

End Class</pre>
<p>Now execute the package and check your desktop for the output file. My output file looked like below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_output_file.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssis output file" border="0" alt="ssis output file" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_output_file_thumb.png" width="644" height="481" /></a> </p>
<p>Now alter your stored procedure so it returns a different resultset. Here&#8217;s another one I used in the AdventureWorks database.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p664code14'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66414"><td class="code" id="p664code14"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> <span style="color: #808080;">&#91;</span>AdventureWorks<span style="color: #808080;">&#93;</span>
GO
<span style="color: #008080;">/****** Object:  StoredProcedure [dbo].[usp_test]    Script Date: 02/20/2010 19:20:55 ******/</span>
<span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
GO
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>
GO
<span style="color: #008080;">-- =============================================</span>
<span style="color: #008080;">-- Author:		Rhys Campbell</span>
<span style="color: #008080;">-- Create date: 2010-02-20</span>
<span style="color: #008080;">-- Description:	Test proc</span>
<span style="color: #008080;">-- =============================================</span>
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>usp_test<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #008080;">-- SET NOCOUNT ON added to prevent extra result sets from</span>
	<span style="color: #008080;">-- interfering with SELECT statements.</span>
	<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>;
&nbsp;
    <span style="color: #008080;">-- Insert statements for procedure here</span>
	<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
	<span style="color: #0000FF;">FROM</span> Person.<span style="color: #202020;">Address</span>;
&nbsp;
<span style="color: #0000FF;">END</span></pre></td></tr></table></div>

<p>Run the package again and you should find another output file on your desktop.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_output_file_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssis output file 2" border="0" alt="ssis output file 2" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssis_output_file_2_thumb.png" width="644" height="481" /></a> </p>
<p>I&#8217;ve not thoroughly tested this code but it appears my initial issues have been resolved. This method does take significantly longer to write the output file than the traditional data flow method. This shouldn&#8217;t be a huge issue for the purposes I&#8217;m thinking of using it in so I should be soon deploying this into a production environment.</p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664">SSIS: Make your output files dynamic part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/ssis-make-your-output-file-dynamic-part-2/664/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Breaking my Non-Equi Join cherry</title>
		<link>http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652</link>
		<comments>http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652#comments</comments>
		<pubDate>Wed, 17 Feb 2010 21:56:16 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[non-equi joins]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652</guid>
		<description><![CDATA[There&#8217;s few SQL techniques you seem to keep in the cupboard gathering dust. I don&#8217;t think I&#8217;ve ever needed to use RIGHT JOIN outside of the classroom. I can recall using FULL OUTER JOIN, just once, to show an employer how not-in-sync their &#34;integrated system&#34; was. Today I broke my professional Non-Equi JOIN cherry!
I basically [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652">Breaking my Non-Equi Join cherry</a></p>
]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s few SQL techniques you seem to keep in the cupboard gathering dust. I don&#8217;t think I&#8217;ve ever needed to use <a href="http://en.wikipedia.org/wiki/Join_(SQL)#Right_outer_joins" target="_blank">RIGHT JOIN</a> outside of the classroom. I can recall using <a href="http://en.wikipedia.org/wiki/Join_(SQL)#Full_outer_join" target="_blank">FULL OUTER JOIN</a>, just once, to show an employer how not-in-sync their &quot;integrated system&quot; was. Today I broke my professional <a href="http://www.orafaq.com/wiki/Nonequi_join" target="_blank">Non-Equi JOIN</a> cherry!</p>
<p>I basically had one table of appointments and another table providing appointment banding by a date range.&#160; The banding wasn&#8217;t consistent, spanning weeks and months,&#160; so there was no possibility of using an equi-join or doing anything with datetime arithmetic. Perhaps that non-equi join thing I remember reading in the textbook will do?</p>
<p>Here&#8217;s a quick run-through of a similar situation. Create some tables and insert some test data. (This first example is in <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> 2005)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p652code19'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p65219"><td class="code" id="p652code19"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">Appointments</span>
<span style="color: #808080;">&#40;</span>
	AppointId <span style="color: #0000FF;">INTEGER</span> <span style="color: #0000FF;">IDENTITY</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	AppointmentDateTime <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	FirstName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	LastName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	Reason <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span>;
GO
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> AppointmentBands
<span style="color: #808080;">&#40;</span>
	AppointBandId <span style="color: #0000FF;">INTEGER</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	StartDateTime <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	EndDateTime <span style="color: #0000FF;">DATETIME</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span>;
GO
&nbsp;
<span style="color: #008080;">-- Insert Test Data</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Appointments</span>
<span style="color: #808080;">&#40;</span>
	AppointmentDateTime,
	FirstName,
	LastName,
	Reason
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-18T17:00:00'</span>,
	   <span style="color: #FF0000;">'Rhys'</span>,
	   <span style="color: #FF0000;">'Campbell'</span>,
	   <span style="color: #FF0000;">'Eye Test'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-23T12:00:00'</span>,
	   <span style="color: #FF0000;">'John'</span>,
	   <span style="color: #FF0000;">'Smith'</span>,
	   <span style="color: #FF0000;">'Ear Test'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-28T14:00:00'</span>,
	   <span style="color: #FF0000;">'Frank'</span>,
	   <span style="color: #FF0000;">'Zappa'</span>,
	   <span style="color: #FF0000;">'Eye Test'</span>;
GO
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">AppointmentBands</span>
<span style="color: #808080;">&#40;</span>
	StartDateTime,
	EndDateTime
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-18T00:00:00'</span>,
	   <span style="color: #FF0000;">'2010-02-22T23:59:59'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-23T00:00:00'</span>,
	   <span style="color: #FF0000;">'2010-02-27T23:59:59'</span>
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'2010-02-28T00:00:00'</span>,
	   <span style="color: #FF0000;">'2010-03-01T23:59:59'</span>;</pre></td></tr></table></div>

<p>I needed to identify which appointment band each record belonged to. It&#8217;s a trivial example here, but the real life situation involved hundreds of thousands of appointments and a few thousand appointment bands. The solution involved using a <a href="http://msdn.microsoft.com/en-us/library/ms187922.aspx" target="_blank">BETWEEN</a> in the join clause.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p652code20'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p65220"><td class="code" id="p652code20"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> app.<span style="color: #808080;">*</span>, band.<span style="color: #202020;">AppointBandId</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">Appointments</span> app
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> dbo.<span style="color: #202020;">AppointmentBands</span> band
	<span style="color: #0000FF;">ON</span> app.<span style="color: #202020;">AppointmentDateTime</span> <span style="color: #808080;">BETWEEN</span> band.<span style="color: #202020;">StartDateTime</span> <span style="color: #808080;">AND</span> band.<span style="color: #202020;">EndDateTime</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/appointments_non_equi_join.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="appointments non equi join" border="0" alt="appointments non equi join" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/appointments_non_equi_join_thumb.png" width="644" height="188" /></a> </p>
<p>Such a simple, elegant, single query solution. Perhaps we need to dust these things off from time-to-time? </p>
<p>Here&#8217;s the same example, a&#8217;la <a href="http://www.mysql.com" target="_blank">MySQL</a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p652code21'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p65221"><td class="code" id="p652code21"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> Appointments
<span style="color: #FF00FF;">&#40;</span>
	AppointId <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span><span style="color: #000033;">,</span>
	AppointmentDateTime <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	FirstName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	LastName <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	Reason <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> AppointmentBands
<span style="color: #FF00FF;">&#40;</span>
	AppointBandId <span style="color: #999900; font-weight: bold;">INTEGER</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span><span style="color: #000033;">,</span>
	StartDateTime <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
	EndDateTime <span style="color: #999900; font-weight: bold;">DATETIME</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Insert Test Data</span>
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> Appointments
<span style="color: #FF00FF;">&#40;</span>
	AppointmentDateTime<span style="color: #000033;">,</span>
	FirstName<span style="color: #000033;">,</span>
	LastName<span style="color: #000033;">,</span>
	Reason
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-18T17:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Rhys'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Campbell'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Eye Test'</span>
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-23T12:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'John'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Smith'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Ear Test'</span>
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-28T14:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Frank'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Zappa'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'Eye Test'</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> AppointmentBands
<span style="color: #FF00FF;">&#40;</span>
	StartDateTime<span style="color: #000033;">,</span>
	EndDateTime
<span style="color: #FF00FF;">&#41;</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-18T00:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'2010-02-22T23:59:59'</span>
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-23T00:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'2010-02-27T23:59:59'</span>
<span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'2010-02-28T00:00:00'</span><span style="color: #000033;">,</span>
	   <span style="color: #008000;">'2010-03-01T23:59:59'</span><span style="color: #000033;">;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p652code22'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p65222"><td class="code" id="p652code22"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> app.<span style="color: #CC0099;">*</span><span style="color: #000033;">,</span> band.AppointBandId
<span style="color: #990099; font-weight: bold;">FROM</span> Appointments app
<span style="color: #990099; font-weight: bold;">INNER</span> <span style="color: #990099; font-weight: bold;">JOIN</span> AppointmentBands band
	<span style="color: #990099; font-weight: bold;">ON</span> app.AppointmentDateTime <span style="color: #CC0099; font-weight: bold;">BETWEEN</span> band.StartDateTime <span style="color: #CC0099; font-weight: bold;">AND</span> band.EndDateTime<span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/MySQL_non_equi_join.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MySQL non equi join" border="0" alt="MySQL non equi join" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/MySQL_non_equi_join_thumb.png" width="644" height="140" /></a></p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652">Breaking my Non-Equi Join cherry</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/breaking-my-non-equi-join-cherry/652/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The &#8216;DataSourceView&#8217; with &#8216;ID&#8217; = &#8216;Adventure Works DW2008&#8242; doesn&#8217;t exist in the collection.</title>
		<link>http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647</link>
		<comments>http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:58:08 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[SSAS]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647</guid>
		<description><![CDATA[One of my goals for this year has been to learn more about SQL Server Analysis Services. So I&#8217;ve bought myself a (very fat) book on the subject and have started to work my way through it. A few days ago I built the first example cube in Chapter two. Coming back to it this [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647">The &#8216;DataSourceView&#8217; with &#8216;ID&#8217; = &#8216;Adventure Works DW2008&#8242; doesn&#8217;t exist in the collection.</a></p>
]]></description>
			<content:encoded><![CDATA[<p>One of <a href="http://www.youdidwhatwithtsql.com/goals-for-2010/514" target="_blank">my goals for this year</a> has been to learn more about <a href="http://msdn.microsoft.com/en-us/library/ms175609(SQL.90).aspx" target="_blank">SQL Server Analysis Services</a>. So I&#8217;ve bought myself a (very fat) book on the subject and have started to work my way through it. A few days ago I built the first example cube in Chapter two. Coming back to it this evening, I opened the project in <a href="http://msdn.microsoft.com/en-us/library/ms173767.aspx" target="_blank">BIDS</a>, and was presented with the following error in the cube designer.</p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="ssas designer data source view collection error" border="0" alt="ssas designer data source view collection error" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_designer_data_source_view_error_thumb.png" width="644" height="175" /></p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_designer_data_source_view_error.png"></a></p>
<p>I recalled renaming the <a href="http://technet.microsoft.com/en-us/library/ms174600.aspx" target="_blank">DataSource View</a>, and have experienced similar issues with renaming objects in <a href="http://www.microsoft.com/sqlserver/2005/en/us/integration-services.aspx" target="_blank">SSIS</a>, so I decided to check out the properties of the DataSourceView.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_data_source_view.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssas data source view" border="0" alt="ssas data source view" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_data_source_view_thumb.png" width="644" height="388" /></a> </p>
<p>Mmmm, the ObjectId here has a &#8216;1&#8242; on the end which implies to me it has been copied and pasted from an original. This info appears to be read only here so I decided to dive into the cubes xml. The xml of a cube can be viewed by right-clicking on it in <a href="http://msdn.microsoft.com/en-us/library/26k97dbc(VS.80).aspx" target="_blank">Solution Explorer</a> and choosing &quot;View Code&quot;.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_cube_xml.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssas_cube_xml" border="0" alt="ssas cube xml thumb The DataSourceView with ID = Adventure Works DW2008 doesnt exist in the collection." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_cube_xml_thumb.png" width="644" height="374" /></a> </p>
<p>I found one reference to <strong>Adventure Works DW2008</strong> in this XML between <strong>&lt;DataSourceViewId&gt;</strong> tags. I changed this to the Id of <strong>Adventure Works DW2008 1</strong> as below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_cube_xml2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssas_cube_xml2" border="0" alt="ssas cube xml2 thumb The DataSourceView with ID = Adventure Works DW2008 doesnt exist in the collection." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_cube_xml2_thumb.png" width="644" height="278" /></a> </p>
<p>I then saved the project and went back to the cube designer.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_designer_data_source_view_error_fixed.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ssas designer data source view error fixed" border="0" alt="ssas designer data source view error fixed" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/ssas_designer_data_source_view_error_fixed_thumb.png" width="644" height="483" /></a> </p>
<p>Excellent. I have repaired my broken cube! Now on with Chapter three!</p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647">The &#8216;DataSourceView&#8217; with &#8216;ID&#8217; = &#8216;Adventure Works DW2008&#8242; doesn&#8217;t exist in the collection.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/the-datasourceview-with-id-adventure-works-dw2008-doesnt-exist-in-the-collection/647/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL clone of sp_spaceused</title>
		<link>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636</link>
		<comments>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636#comments</comments>
		<pubDate>Sun, 14 Feb 2010 16:58:03 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sp_spaceused]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636</guid>
		<description><![CDATA[Following on from yesterdays blog post, a MySQL clone of sp_MsForEachTable, here&#8217;s an attempt at a clone of sp_spaceused. There&#8217;s a few issues to be aware of involving the storage engine in use. For example the row count is accurate for MyISAM while with InnoDb it seems to be just an estimate. This estimate can [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636">MySQL clone of sp_spaceused</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Following on from yesterdays blog post, a <a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624" target="_blank">MySQL clone of sp_MsForEachTable</a>, here&#8217;s an attempt at a clone of <a href="http://msdn.microsoft.com/en-us/library/ms188776.aspx" target="_blank">sp_spaceused</a>. There&#8217;s a few issues to be aware of involving the storage engine in use. For example the row count is accurate for <a href="http://en.wikipedia.org/wiki/MyISAM" target="_blank">MyISAM</a> while with <a href="http://en.wikipedia.org/wiki/InnoDB" target="_blank">InnoDb</a> it seems to be just an estimate. This estimate can vary from execution-to-execution. The procedure derives its information from <a href="http://dev.mysql.com/doc/refman/5.1/en/tables-table.html" target="_blank">INFORMATION_SCHEMA.TABLES</a>. To get started create the below procedure in the database you wish to use it in.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code26'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63626"><td class="code" id="p636code26"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
&nbsp;
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>mysql<span style="color: #008080; font-weight: bold;">_</span>spaceused`</span>$$
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>mysql<span style="color: #008080; font-weight: bold;">_</span>spaceused`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> var_tablename <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">LANGUAGE SQL</span>
    <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
    <span style="color: #990099; font-weight: bold;">COMMENT</span> <span style="color: #008000;">'Clone of MSSQL sp<span style="color: #008080; font-weight: bold;">_</span>spaceused'</span>
    <span style="color: #990099; font-weight: bold;">BEGIN</span>
	<span style="color: #808080; font-style: italic;"># Based on http://msdn.microsoft.com/en-us/library/ms188776.aspx</span>
	<span style="color: #009900;">IF</span> var_tablename <span style="color: #CC0099;">=</span> <span style="color: #008000;">''</span> <span style="color: #CC0099; font-weight: bold;">OR</span> var_tablename <span style="color: #CC0099; font-weight: bold;">IS</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #009900;">THEN</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">-- db info, unallocated_space only reported for InnoDB tables</span>
		<span style="color: #990099; font-weight: bold;">SELECT</span> table_schema <span style="color: #990099; font-weight: bold;">AS</span> database_name<span style="color: #000033;">,</span>
		       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_length <span style="color: #CC0099;">+</span> index_length <span style="color: #CC0099;">+</span> data_free<span style="color: #FF00FF;">&#41;</span><span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> database_size<span style="color: #000033;">,</span>
		       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_free<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> unallocated_space
		<span style="color: #990099; font-weight: bold;">FROM</span> information_schema.<span style="color: #990099; font-weight: bold;">TABLES</span>
		<span style="color: #990099; font-weight: bold;">WHERE</span> table_schema <span style="color: #CC0099;">=</span> <span style="color: #000099;">DATABASE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
		<span style="color: #990099; font-weight: bold;">GROUP BY</span> table_schema<span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_length <span style="color: #CC0099;">+</span> index_length <span style="color: #CC0099;">+</span> data_free<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> reserved<span style="color: #000033;">,</span>
		       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_length<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #990099; font-weight: bold;">data</span><span style="color: #000033;">,</span>
		       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>index_length<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> index_size<span style="color: #000033;">,</span>
		       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_free<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> unused
		<span style="color: #990099; font-weight: bold;">FROM</span> information_schema.<span style="color: #990099; font-weight: bold;">TABLES</span>
		<span style="color: #990099; font-weight: bold;">WHERE</span> TABLE_SCHEMA <span style="color: #CC0099;">=</span> <span style="color: #000099;">DATABASE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #009900;">ELSE</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">-- table info</span>
		<span style="color: #808080; font-style: italic;">-- does the table exist in the current db?</span>
		<span style="color: #990099; font-weight: bold;">IF <span style="color: #CC0099; font-weight: bold;">NOT</span> EXISTS</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">1</span> <span style="color: #990099; font-weight: bold;">FROM</span> information_schema.<span style="color: #990099; font-weight: bold;">TABLES</span> <span style="color: #990099; font-weight: bold;">WHERE</span> TABLE_NAME <span style="color: #CC0099;">=</span> var_tablename<span style="color: #FF00FF;">&#41;</span> <span style="color: #009900;">THEN</span>
&nbsp;
			<span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008000;">'Table does not exist.'</span> <span style="color: #990099; font-weight: bold;">AS</span> error<span style="color: #000033;">;</span>
		<span style="color: #009900;">ELSE</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">-- rows is estimate based for InnoDb (often a fair bit out)</span>
			<span style="color: #808080; font-style: italic;">-- MyISAM is accurate</span>
			<span style="color: #990099; font-weight: bold;">SELECT</span> var_tablename <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #008000;">`name`</span><span style="color: #000033;">,</span>
			       table_rows <span style="color: #990099; font-weight: bold;">AS</span> rows<span style="color: #000033;">,</span>
			       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_length <span style="color: #CC0099;">+</span> index_length <span style="color: #CC0099;">+</span> data_free<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> reserved<span style="color: #000033;">,</span>
			       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_length<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #990099; font-weight: bold;">data</span><span style="color: #000033;">,</span>
			       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>index_length<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> index_size<span style="color: #000033;">,</span>
			       <span style="color: #000099;">CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">ROUND</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">SUM</span><span style="color: #FF00FF;">&#40;</span>data_free<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099;">/</span> <span style="color: #008080;">1024</span> <span style="color: #CC0099;">/</span><span style="color: #008080;">1024</span><span style="color: #000033;">,</span> <span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #008000;">'(MB)'</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> unused <span style="color: #808080; font-style: italic;">-- InnoDb only MySQL 5.1.28</span>
			<span style="color: #990099; font-weight: bold;">FROM</span> information_schema.<span style="color: #990099; font-weight: bold;">TABLES</span>
			<span style="color: #990099; font-weight: bold;">WHERE</span> TABLE_SCHEMA <span style="color: #CC0099;">=</span> <span style="color: #000099;">DATABASE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span>
			<span style="color: #CC0099; font-weight: bold;">AND</span> TABLE_NAME <span style="color: #CC0099;">=</span> var_tablename<span style="color: #000033;">;</span>
&nbsp;
		<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
&nbsp;
    <span style="color: #009900;">END</span>$$
&nbsp;
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Usage is as follows.</p>
<p><strong>Get database size information</strong></p>
<p>To get database level information the procedure should be called with an empty string or NULL.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code27'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63627"><td class="code" id="p636code27"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Empty string or null to get db info</span>
<span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_spaceused<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">''</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Two resultset are returned. Similar to the ones described on the <a href="http://msdn.microsoft.com/en-us/library/ms188776.aspx" target="_blank">sp_spaceused documentation</a> page.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_resultset_1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="usp_mysql_spaceused resultset 1" border="0" alt="usp_mysql_spaceused resultset 1" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_resultset_1_thumb.png" width="644" height="160" /></a> </p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_resultset_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="usp_mysql_spaceused resultset 2" border="0" alt="usp_mysql_spaceused resultset 2" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_resultset_2_thumb.png" width="644" height="175" /></a> </p>
<p><strong>Get table size information</strong></p>
<p><font color="#666666">To get information on the size of a table just call the procedure with the appropriate table name.</font></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p636code28'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63628"><td class="code" id="p636code28"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_spaceused<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'City'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_table_resultset.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="usp_mysql_spaceused_table_resultset" border="0" alt="usp mysql spaceused table resultset thumb MySQL clone of sp spaceused" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/usp_mysql_spaceused_table_resultset_thumb.png" width="644" height="131" /></a></p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636">MySQL clone of sp_spaceused</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_spaceused/636/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL clone of sp_msforeachtable</title>
		<link>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624</link>
		<comments>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624#comments</comments>
		<pubDate>Sat, 13 Feb 2010 19:56:47 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sp_MsForEachTale]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624</guid>
		<description><![CDATA[Many SQL Server DBAs and Developers get a  lot of use out of the undocumented sp_MsForEachTable system stored procedure. Here&#8217;s an attempt at creating a functional version for MySQL. The procedure makes use of prepared statements, which do have some limitations, so some uses may not translate across. This is far from production ready so [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624">MySQL clone of sp_msforeachtable</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Many <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> DBAs and Developers get a  lot of use out of the <a href="http://connect.microsoft.com/SQLServer/feedback/details/264676/sp-msforeachtable-provide-supported-documented-version" target="_blank">undocumented sp_MsForEachTable</a> system stored procedure. Here&#8217;s an attempt at creating a functional version for <a href="http://www.mysql.com" target="_blank">MySQL</a>. The procedure makes use of <a href="http://rpbouman.blogspot.com/2005/11/mysql-5-prepared-statement-syntax-and.html" target="_blank">prepared statements</a>, which do have some limitations, so some uses may not translate across. This is far from production ready so use with lots of caution.</p>
<p>Create the below stored procedure in the database you wish to use it in.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code35'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62435"><td class="code" id="p624code35"><pre class="mysql" style="font-family:monospace;">DELIMITER $$
&nbsp;
<span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> <span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>mysql<span style="color: #008080; font-weight: bold;">_</span>foreachtable`</span>$$
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">PROCEDURE</span> <span style="color: #008000;">`usp<span style="color: #008080; font-weight: bold;">_</span>mysql<span style="color: #008080; font-weight: bold;">_</span>foreachtable`</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">IN</span> sql_string <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1000</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span>
    <span style="color: #990099; font-weight: bold;">LANGUAGE SQL</span>
    <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #990099; font-weight: bold;">DETERMINISTIC</span>
    <span style="color: #990099; font-weight: bold;">COMMENT</span> <span style="color: #008000;">'Functional clone of sp<span style="color: #008080; font-weight: bold;">_</span>MsForEachTable'</span>
    <span style="color: #990099; font-weight: bold;">BEGIN</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">DECLARE</span> var_tablename <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">DECLARE</span> last_row <span style="color: #999900; font-weight: bold;">BIT</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">DECLARE</span> table_cursor CURSOR FOR <span style="color: #990099; font-weight: bold;">SELECT</span> TABLE_NAME
					<span style="color: #990099; font-weight: bold;">FROM</span> information_schema.<span style="color: #990099; font-weight: bold;">TABLES</span>
					<span style="color: #990099; font-weight: bold;">WHERE</span> TABLE_TYPE <span style="color: #CC0099;">=</span> <span style="color: #008000;">'BASE TABLE'</span>
					<span style="color: #CC0099; font-weight: bold;">AND</span> TABLE_SCHEMA <span style="color: #CC0099;">=</span> <span style="color: #000099;">DATABASE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">DECLARE</span> CONTINUE <span style="color: #990099; font-weight: bold;">HANDLER</span> FOR <span style="color: #CC0099; font-weight: bold;">NOT</span> FOUND <span style="color: #990099; font-weight: bold;">SET</span> last_row <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span><span style="color: #000033;">;</span>
&nbsp;
	OPEN table_cursor<span style="color: #000033;">;</span>
	FETCH table_cursor <span style="color: #990099; font-weight: bold;">INTO</span> var_tablename<span style="color: #000033;">;</span>
&nbsp;
	<span style="color: #990099; font-weight: bold;">SET</span> last_row <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span><span style="color: #000033;">;</span>
	<span style="color: #990099; font-weight: bold;">SET</span> @var <span style="color: #CC0099;">=</span> <span style="color: #008000;">''</span><span style="color: #000033;">;</span>
&nbsp;
	lbl_table_cursor: LOOP
&nbsp;
		<span style="color: #990099; font-weight: bold;">SET</span> @qry <span style="color: #CC0099;">=</span> <span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span>sql_string<span style="color: #000033;">,</span> <span style="color: #008000;">'?'</span><span style="color: #000033;">,</span> var_tablename<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
&nbsp;
		PREPARE q <span style="color: #990099; font-weight: bold;">FROM</span> @qry<span style="color: #000033;">;</span>
		EXECUTE q<span style="color: #000033;">;</span>
		DEALLOCATE PREPARE q<span style="color: #000033;">;</span>
&nbsp;
		FETCH table_cursor <span style="color: #990099; font-weight: bold;">INTO</span> var_tablename<span style="color: #000033;">;</span>
		<span style="color: #009900;">IF</span> last_row <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #009900;">THEN</span>
			LEAVE lbl_table_cursor<span style="color: #000033;">;</span>
		<span style="color: #009900;">END</span> <span style="color: #009900;">IF</span><span style="color: #000033;">;</span>
	<span style="color: #009900;">END</span> LOOP lbl_table_cursor<span style="color: #000033;">;</span>
&nbsp;
	CLOSE table_cursor<span style="color: #000033;">;</span>
&nbsp;
    <span style="color: #009900;">END</span>$$
&nbsp;
DELIMITER <span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Usage is quite simple, just pass in a query with a &#8216;?&#8217; in place of where the table name should be. I have verified the below use cases function as expected.</p>
<p><strong>Select 5 rows from each table</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code36'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62436"><td class="code" id="p624code36"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_foreachtable<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'SELECT * FROM ? LIMIT 5;'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><strong>Count the number of rows in each table</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code37'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62437"><td class="code" id="p624code37"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_foreachtable<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'SELECT '</span><span style="color: #008000;">'?'</span><span style="color: #008000;">', COUNT(*) AS Rows FROM ?'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><strong>Repair all tables in the database</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code38'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62438"><td class="code" id="p624code38"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_foreachtable<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'REPAIR TABLE ?'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><strong>Change all tables to use the InnoDb storage engine</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code39'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62439"><td class="code" id="p624code39"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_foreachtable<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'ALTER TABLE ? ENGINE=InnoDB'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p><strong>Reset the AUTO_INCREMENT to zero in all tables</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p624code40'); return false;">View Code</a> MYSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62440"><td class="code" id="p624code40"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CALL</span> usp_mysql_foreachtable<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'ALTER TABLE ? AUTO<span style="color: #008080; font-weight: bold;">_</span>INCREMENT = 0'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624">MySQL clone of sp_msforeachtable</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/mysql-clone-of-sp_msforeachtable/624/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing Index Fragmentation with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622</link>
		<comments>http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622#comments</comments>
		<pubDate>Tue, 09 Feb 2010 22:24:41 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[index fragmentation]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[Powershell Scripting]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622</guid>
		<description><![CDATA[Here&#8217;s a Powershell script that can be used to manage index fragmentation in SQL Server databases. The strategy I&#8217;ve used in the script is based on a recommendation from Pinal Dave (blog &#124; twitter) in his article&#160; Difference Between Index Rebuild and Index Reorganize Explained with T-SQL Script. Just set the $sqlserver and $database variables [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622">Managing Index Fragmentation with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> script that can be used to manage index fragmentation in <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> databases. The strategy I&#8217;ve used in the script is based on a recommendation from Pinal Dave (<a href="http://blog.sqlauthority.com" target="_blank">blog</a> | <a href="http://twitter.com/pinaldave" target="_blank">twitter</a>) in his article&nbsp; <a href="http://blog.sqlauthority.com/2007/12/22/sql-server-difference-between-index-rebuild-and-index-reorganize-explained-with-t-sql-script/" target="_blank">Difference Between Index Rebuild and Index Reorganize Explained with T-SQL Script</a>. Just set the <strong>$sqlserver </strong>and <strong>$database </strong>variables to something appropriate for your environment. Enjoy!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p622code42'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p62242"><td class="code" id="p622code42"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Load SMO</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">'Microsoft.SqlServer.SMO'</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>;
&nbsp;
<span style="color: #008000;"># Set sql server and database name here</span>
<span style="color: #800080;">$sqlserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost\sql2005&quot;</span>;
<span style="color: #800080;">$database</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;AdventureWorks&quot;</span>;
&nbsp;
<span style="color: #800080;">$srv</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #800000;">&quot;Microsoft.SqlServer.Management.SMO.Server&quot;</span> <span style="color: #800080;">$sqlserver</span>;
<span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.SqlServer.Management.SMO.Database&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$srv</span>.Databases<span style="color: #000000;">&#91;</span><span style="color: #800080;">$database</span><span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #008000;"># Get table count</span>
<span style="color: #800080;">$table_count</span> <span style="color: pink;">=</span> <span style="color: #800080;">$db</span>.Tables.Count;
<span style="color: #800080;">$i</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>;
&nbsp;
<span style="color: #008000;"># First script out the drops</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$table</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$db</span>.Tables<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Write-Progress</span> <span style="color: #008080; font-style: italic;">-Activity</span> <span style="color: #800000;">&quot;Checking table $table&quot;</span> <span style="color: #008080; font-style: italic;">-PercentComplete</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">/</span> <span style="color: #800080;">$table_count</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">*</span> <span style="color: #804000;">100</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Status</span> <span style="color: #800000;">&quot;Processing indexes&quot;</span> <span style="color: #008080; font-style: italic;">-Id</span> <span style="color: #804000;">1</span>;
	<span style="color: #800080;">$i</span><span style="color: pink;">++</span>;
	<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$index</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$table</span>.Indexes<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$index_name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$index</span>.Name;
		<span style="color: #008080; font-weight: bold;">Write-Progress</span> <span style="color: #008080; font-style: italic;">-Activity</span> <span style="color: #800000;">&quot;Checking table $table&quot;</span> <span style="color: #008080; font-style: italic;">-PercentComplete</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: pink;">/</span> <span style="color: #800080;">$table_count</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">*</span> <span style="color: #804000;">100</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Status</span> <span style="color: #800000;">&quot;Processing index $index_name&quot;</span> <span style="color: #008080; font-style: italic;">-Id</span> <span style="color: #804000;">1</span>;
		<span style="color: #008000;"># Get the fragmentation stats</span>
		<span style="color: #800080;">$frag_stats</span> <span style="color: pink;">=</span> <span style="color: #800080;">$index</span>.EnumFragmentation<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #008000;"># Get the properties we need to work with the index</span>
		<span style="color: #800080;">$frag_stats</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #000000;">&#123;</span>
						<span style="color: #800080;">$Index_Name</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span>.Index_Name;
						<span style="color: #800080;">$Index_Type</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span>.Index_Type;
						<span style="color: #800080;">$Average_Fragmentation</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span>.AverageFragmentation;
									<span style="color: #000000;">&#125;</span>;
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green <span style="color: #800000;">&quot;$Index_Type $Index_Name has a fragmentation percentage of $Average_Fragmentation&quot;</span>;
&nbsp;
		<span style="color: #008000;"># Here we decide what to do based on the level on fragmentation</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Average_Fragmentation</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">40.00</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red <span style="color: #800000;">&quot;$Index_Name is more than 40% fragmented and will be rebuilt.&quot;</span>;
			<span style="color: #800080;">$index</span>.Rebuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green <span style="color: #800000;">&quot;$Index_Name has been rebuilt.&quot;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">elseif</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Average_Fragmentation</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">10.00</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$Average_Fragmentation</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">40.00</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red <span style="color: #800000;">&quot;$Index_Name is between 10-40% fragmented and will be reorganized.&quot;</span>;
			<span style="color: #800080;">$index</span>.Reorganize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green <span style="color: #800000;">&quot;$Index_Name has been reorganized.&quot;</span>;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red <span style="color: #800000;">&quot;$Index_Name is healthy, with $Average_Fragmentation% fragmentation, and will be left alone.&quot;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-weight: bold;">Write-Progress</span> <span style="color: #008080; font-style: italic;">-Activity</span> <span style="color: #800000;">&quot;Finished processing <span style="color: #008080; font-weight: bold;">`&quot;</span>$database<span style="color: #008080; font-weight: bold;">`&quot;</span> indexes.&quot;</span> <span style="color: #008080; font-style: italic;">-PercentComplete</span> <span style="color: #804000;">100</span> <span style="color: #008080; font-style: italic;">-Status</span> <span style="color: #800000;">&quot;Done&quot;</span> <span style="color: #008080; font-style: italic;">-Id</span> <span style="color: #804000;">1</span>;
<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">2</span>;</pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/AdventureWork_Index_Management.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="AdventureWork Index Management with Powershell" border="0" alt="AdventureWork Index Management with Powershell" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/AdventureWork_Index_Management_thumb.png" width="644" height="373" /></a></p>
<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622">Managing Index Fragmentation with Powershell</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/managing-index-fragmentation-with-powershell/622/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
