<?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>tim laqua dot com</title>
	<atom:link href="http://timlaqua.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Sun, 09 May 2010 15:25:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Excel 2007 Hangs When Trying to Edit an OLAP Cube Filter</title>
		<link>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/</link>
		<comments>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 03:38:16 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[pivot table]]></category>
		<category><![CDATA[ssas]]></category>
		<category><![CDATA[xmla]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=371</guid>
		<description><![CDATA[Ok, it doesn't hang every time you try to edit an OLAP cube filter, but sometimes - it appears to. In reality, I've never seen it permanently hang - just kind of go away for a while. Here's the basic symptom that the business will report to you: "Excel freezes (or hangs) when I try [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it doesn't hang every time you try to edit an OLAP cube filter, but sometimes - it appears to.  In reality, I've never seen it permanently hang - just kind of go away for a while.  Here's the basic symptom that the business will report to you:</p>
<p><em>"Excel freezes (or hangs) when I try to change this filter"</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png" alt="" title="DeliveryDate-Date-Broken" width="352" height="351" class="alignnone size-full wp-image-373" /></a></p>
<p>Most of us have seen this at one point or another and shrugged it off as a busy time or processing is going on or there are cats clogging up the tubes, etc.  Tonight, I finally decided to figure out what's causing it.<br />
<span id="more-371"></span><br />
When you have an OLAP cube filter in your pivot table and expand the items list to select your filter items, Excel fires a bunch of Discover commands at the cube (these are pretty light in most cases).  If you don't have anything selected yet (so you just have the default member selected) Excel isn't doing much work here and the list pops right up.  Here's two basic flow examples for what discover commands are fired off when you DO have an item selected:</p>
<p>If you have one level 1 member selected</p>
<ol>
<li>MDSCHEMA_CUBES (whatever cube you're connected to)</li>
<li>MDSCHEMA_CUBES (again, same thing)</li>
<li>MDSCHEMA_MEMBERS (LEVEL_UNIQUE_NAME of the filter), no TREE_OP</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member) TREE_OP 4, only immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 1, returns all children</li>
</ol>
<p>If you have one level 2 member selected in a hierarchy</p>
<ol>
<li>MDSCHEMA_CUBES (whatever cube you're connected to)</li>
<li>MDSCHEMA_CUBES (again, same thing)</li>
<li>MDSCHEMA_MEMBERS (LEVEL_UNIQUE_NAME of the filter), no TREE_OP</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member) TREE_OP 4, only immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent)  TREE_OP 4, immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent)  TREE_OP 1, all children</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 1, returns all children</li>
</ol>
<p>So, that's six requests for a level 1 member and 9 requests for a level 2 member - both of these take milliseconds to complete the whole flow, so no big deal.  When does this become a big deal?  When you do something like click the "Select multiple items" checkbox, expand a hierarchy and UNCHECK something... like if you opened the Adventure Works 2008 cube, added Delivery Date.Date as a filter, expanded the "All Periods" level and deselected the first day:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Setup.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Setup.png" alt="" title="DeliveryDate-Date-Setup" width="312" height="418" class="alignnone size-full wp-image-372" /></a></p>
<p>Now click OK and expand the items box - we get a familiar popup:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png" alt="" title="DeliveryDate-Date-Broken" width="352" height="351" class="alignnone size-full wp-image-373" /></a></p>
<p>It comes back after a few seconds with the expected item list, but why did it take so long?  Well, based on our flows above, we have a whole bunch of level 1 members selected - 1187 of them to be exact.  That means there will be 1187 requests for their parent member (TREE_OP 4) which will all return the [All Periods] member.  To illustrate this, I traced that exact operation:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Profiler.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Profiler-300x144.png" alt="" title="DeliveryDate-Date-Profiler" width="300" height="144" class="alignnone size-medium wp-image-374" /></a></p>
<p>The profiler captured 1192 discover requests - 1187 of them were getting the parents of selected members, two were MDSCHEMA_CUBES requests, one was getting [All Periods], one was getting all the children of [All Periods], and one was getting the Unique Name of the root level.  Not cool.  Imagine what happens when your talking about tens of thousands of members at a particular level!  Granted, that seems unlikely but understand that the logic behind this is "I don't want to see this", "hide just this member", and so forth - in some cases people have no idea what actually happened was they unchecked one of 6,000 members.</p>
<p>So what to do about this?  Educate.  To fix the immediate problem of a seemingly broken Excel pivot table - just wait for the filter to load, it'll come back eventually.  In the future when working with Excel filters, always favor selecting vs. deselecting and filtering at higher levels in the hierarchy whenever possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Locating Rampant Database Growth</title>
		<link>http://timlaqua.com/2010/03/locating-rampant-database-growth/</link>
		<comments>http://timlaqua.com/2010/03/locating-rampant-database-growth/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 17:40:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=358</guid>
		<description><![CDATA[Every now and then you get a helpful alert from one of your database servers about disk space being low (you're monitoring that, right?), or a bunch of autogrowth alerts (you're monitoring that too, right?) - but what happens when you get these for a database that you don't expect growth in? Further, what happens [...]]]></description>
			<content:encoded><![CDATA[<p>Every now and then you get a helpful alert from one of your database servers about disk space being low (you're monitoring that, right?), or a bunch of autogrowth alerts (you're monitoring that too, right?) - but what happens when you get these for a database that you don't expect growth in?  Further, what happens when that database is growing rampantly (say like 1GB/hr in my case) and it's a canned database from a 3rd party product?  This time it was the database that SolarWinds uses for collection - and apparently it was collecting a lot of something that it wasn't collecting before.</p>
<ol>
<li>you send out an email asking the end users of the system (IT in this case) if anything changed</li>
<li>adjust so said system stops trying to fill up your drives</li>
</ol>
<p>Unfortunately, there's often quite a few possibilities for "why" a database is growing - and when it's a canned product, you don't always have the best understanding of why it does what it does when it does it.  As a Database Admin, you can help diagnose the problem by letting everyone know what exactly is growing:<br />
<span id="more-358"></span><br />
First, figure out what table is growing:<br />
<em>spSpaceUsed.sql</em></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#Temp_SpSpaceUsed</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>rows<span style="color: #66cc66;">&#93;</span> INT
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>reserved<span style="color: #66cc66;">&#93;</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#93;</span>	VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>index_size<span style="color: #66cc66;">&#93;</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>unused<span style="color: #66cc66;">&#93;</span> VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>CreatedTime<span style="color: #66cc66;">&#93;</span> DATETIME <span style="color: #993333; font-weight: bold;">DEFAULT</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
EXEC sp_msforeachtable <span style="color: #ff0000;">'INSERT INTO #Temp_SpSpaceUsed ([name],[rows],[reserved],[data],[index_size],[unused]) EXEC sp_spaceused [?]'</span>
&nbsp;
WAITFOR DELAY <span style="color: #ff0000;">'00:01:00'</span>
&nbsp;
EXEC sp_msforeachtable <span style="color: #ff0000;">'INSERT INTO #Temp_SpSpaceUsed ([name],[rows],[reserved],[data],[index_size],[unused]) EXEC sp_spaceused [?]'</span>
&nbsp;
;WITH SpSpaceUsed <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> 
		<span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span>
		<span style="color: #66cc66;">,</span>CAST<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> INT<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>CreatedTime<span style="color: #66cc66;">&#93;</span>
		<span style="color: #66cc66;">,</span>ROW_NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> OVER <span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#91;</span>CreatedTime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>RowNumber<span style="color: #66cc66;">&#93;</span>
	<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">#Temp_SpSpaceUsed	</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> 
	 a<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>b<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #66cc66;">-</span> a<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>GrowthKB<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span>CAST<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #66cc66;">-</span> a<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">AS</span> FLOAT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> DateDiff<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> a<span style="color: #66cc66;">.</span>CreatedTime<span style="color: #66cc66;">,</span> b<span style="color: #66cc66;">.</span>CreatedTime<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1000.0</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60.0</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60.0</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>GrowthKBPerHour<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> SpSpaceUsed a
	<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> SpSpaceUsed b
		<span style="color: #993333; font-weight: bold;">ON</span> a<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span>
			<span style="color: #993333; font-weight: bold;">AND</span> a<span style="color: #66cc66;">.</span>RowNumber <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>
			<span style="color: #993333; font-weight: bold;">AND</span> b<span style="color: #66cc66;">.</span>RowNumber <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span>
	GrowthKBPerHour <span style="color: #993333; font-weight: bold;">DESC</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#Temp_SpSpaceUsed</span></pre></div></div>

<p>Next, look at the culprit (assuming there's one table doing all the damage - I've found that's usually the case) and try to decipher the column names.  Finally, run a few queries against the table - WITH(NOLOCK) of course - hey, this table is pretty busy.  Now try and see where all the action is coming from.  In this case, one of the columns was [IP] so I just did a COUNT(1) by IP for the last hour's records.  Sure enough, 99% of the records were coming from a single IP, sent that IP off to the guys who know what IPs mean, and they knew exactly which change caused the growth.</p>
<p>Bottom line - nobody knows everything about everything, but we can learn pretty quick with the right information.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/03/locating-rampant-database-growth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script sp_configure Output To Migrate Settings Between SQL Servers</title>
		<link>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/</link>
		<comments>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 23:22:30 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=355</guid>
		<description><![CDATA[Sometimes when setting up a new server, all you want is for it to work and be configured exactly like the old server. In some cases, the new server is almost identical in every way already. If you've worked much with SQL Server, you know very well that there are a billion switches and knobs [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when setting up a new server, all you want is for it to work and be configured exactly like the old server.  In some cases, the new server is almost identical in every way already.  If you've worked much with SQL Server, you know very well that there are a billion switches and knobs and every time you do this, you forget at least one.  I had a similar situation recently and figured I'd be lazy about it and just turned the output of sp_configure in to a script I could execute on the new server:<br />
<span id="more-355"></span><br />
<em>scriptSpConfigure.sql - run this on the old/source server</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">1</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO
<span style="color: #0000FF;">DECLARE</span> @spConfigureOutput <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>name<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#91;</span>minimum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>maximum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>config_value<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>run_value<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @spConfigureOutput
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>	<span style="color: #FF0000;">'EXEC sp_configure '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">', '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>config_value <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span>	@spConfigureOutput
GO
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">0</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO</pre></div></div>

<p>Copy the selected rows and paste in to another SSMS window, add the show advanced options switch above and below - should end up with something like this after you <strong>remove all the settings you don't care about or don't want on the new server</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">1</span>;
GO
<span style="color: #0000FF;">RECONFIGURE</span>;
GO
&nbsp;
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Ad Hoc Distributed Queries'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Agent XPs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'clr enabled'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'cost threshold for parallelism'</span>, <span style="color: #000;">5</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'cursor threshold'</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'Database Mail XPs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'default full-text language'</span>, <span style="color: #000;">1033</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'default trace enabled'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'fill factor (%)'</span>, <span style="color: #000;">80</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'ft crawl bandwidth (max)'</span>, <span style="color: #000;">100</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'ft notify bandwidth (max)'</span>, <span style="color: #000;">100</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max full-text crawl range'</span>, <span style="color: #000;">4</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max server memory (MB)'</span>, <span style="color: #000;">10000</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'max text repl size (B)'</span>, <span style="color: #000;">65536</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'min memory per query (KB)'</span>, <span style="color: #000;">1024</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'min server memory (MB)'</span>, <span style="color: #000;">10000</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'nested triggers'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'network packet size (B)'</span>, <span style="color: #000;">4096</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'PH timeout (s)'</span>, <span style="color: #000;">60</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'query wait (s)'</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote access'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote login timeout (s)'</span>, <span style="color: #000;">20</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'remote query timeout (s)'</span>, <span style="color: #000;">900</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'scan for startup procs'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'server trigger recursion'</span>, <span style="color: #000;">1</span>
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'SMO and DMO XPs'</span>, <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_CONFIGURE</span> <span style="color: #FF0000;">'show advanced options'</span> , <span style="color: #000;">0</span>;
<span style="color: #0000FF;">RECONFIGURE</span>;
GO;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/script-sp_configure-output-to-migrate-settings-between-sql-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script RESTORE DATABASE &#8230; WITH MOVE Stub</title>
		<link>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/</link>
		<comments>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 18:29:26 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=349</guid>
		<description><![CDATA[I think most people setup the drives on their Development servers to match their Production servers - this is so that restores go smoothly and files go where they're supposed to, things match up nicely, etc. Unfortunately, when you create a full backup all the backup file contains is the logical name of all the [...]]]></description>
			<content:encoded><![CDATA[<p>I think most people setup the drives on their Development servers to match their Production servers - this is so that restores go smoothly and files go where they're supposed to, things match up nicely, etc.  Unfortunately, when you create a full backup all the backup file contains is the logical name of all the files - no physical paths.  This means that if the database doesn't exist on the destination server yet, the engine has absolutely no idea where to put the files or what to name them.</p>
<p>The following script can be executed in the context of the source (original) database that was backed up to script out the MOVE statements if your plan is to put the files in the same place on the destination server.<br />
<span id="more-349"></span><br />
<em>scriptRestoreWithMove.sql - run this in the context of the source database</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @MoveOption <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</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;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'RESTORE DATABASE '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #008080;">-- Edit this to match where you're restoring from</span>
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'FROM DISK = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.bak'</span><span style="color: #FF0000;">''</span>  
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'WITH'</span>
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @MoveOption <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span>
    <span style="color: #FF0000;">'MOVE '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> a.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' TO '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> a.<span style="color: #202020;">FILENAME</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>MOVE <span style="color: #0000FF;">OPTION</span><span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span>
    dbo.<span style="color: #202020;">sysfiles</span> a
&nbsp;
<span style="color: #0000FF;">DECLARE</span> 
	 @LastId <span style="color: #0000FF;">INT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
	,@MoveOptionText <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">EXISTS</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">FROM</span> @MoveOption <span style="color: #0000FF;">WHERE</span> <span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&gt;</span> @LastId<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SELECT</span> 		<span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span>
			 @MoveOptionText <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>MoveOption<span style="color: #808080;">&#93;</span> 
			,@LastId <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span>
	<span style="color: #0000FF;">FROM</span>		@MoveOption
	<span style="color: #0000FF;">WHERE</span>		<span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&gt;</span> @LastId
	<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>	<span style="color: #808080;">&#91;</span>Id<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">ASC</span>
&nbsp;
	<span style="color: #0000FF;">PRINT</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> @LastId <span style="color: #808080;">=</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">','</span> <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> @MoveOptionText
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'GO'</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'ALTER DATABASE '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' SET MULTI_USER'</span>
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'GO'</span></pre></div></div>

<p><em>And the output looks like this:</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">RESTORE</span> <span style="color: #0000FF;">DATABASE</span> AdventureWorksDW
<span style="color: #0000FF;">FROM</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'AdventureWorksDW.bak'</span>
<span style="color: #0000FF;">WITH</span>
MOVE <span style="color: #FF0000;">'AdventureWorksDW_Data'</span> <span style="color: #0000FF;">TO</span> <span style="color: #FF0000;">'D:<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW_Data.mdf'</span>
,MOVE <span style="color: #FF0000;">'AdventureWorksDW_Log'</span> <span style="color: #0000FF;">TO</span> <span style="color: #FF0000;">'T:<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW<span style="color: #000099; font-weight: bold;">\A</span>dventureWorksDW_Log.LDF'</span>
GO
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> AdventureWorksDW <span style="color: #0000FF;">SET</span> MULTI_USER
GO</pre></div></div>

<p>If you end up wanting to do something similar with existing databases, make sure to add a command before the RESTORE to set SINGLE_USER mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/script-restore-database-with-move-stub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VersionOne Nag: Reminding Us To Burn Our Points</title>
		<link>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/</link>
		<comments>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 04:19:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[version one]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=341</guid>
		<description><![CDATA[You'll forget - we all do. After a hard day of work, the last thing that pops in to your head is "hey, I should go update this story in VersionOne before I go home." Oh no, the only thing you're thinking about is how bad traffic will be, what you're having for dinner, your [...]]]></description>
			<content:encoded><![CDATA[<p>You'll forget - we all do.  After a hard day of work, the last thing that pops in to your head is "hey, I should go update this story in VersionOne before I go home."  Oh no, the only thing you're thinking about is how bad traffic will be, what you're having for dinner, your trip to Seattle, which bar has the best drink specials tonight, etc.  So accepting that we forget to burn points now and then, why don't we just make a script to remind us?  While you're at it, might as well add a reminder for when you accidentally close a story without setting the ToDo points to zero.</p>
<p>Luckily, since you obviously use VersionOne (because it's the gold standard), there's an API for that:<br />
<span id="more-341"></span><br />
<em>Note:  The following script will request your VersionOne username and password via Read-Host - if you want this to run every day at 4pm, you need to embed your username and password somewhere (securestring support in powershell is helpful, but still - nothing's perfect in this scenario unless you can use LDAP auth)</em></p>
<p><strong>PowerShell script: v1Nag.ps1</strong></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$emailFrom</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;whoever.replies@shouldgoto.com&quot;</span>
<span style="color: #800080;">$emailSMTPServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;your.smtpserver.com&quot;</span>
<span style="color: #800080;">$teamName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Your Team Name in VersionOne&quot;</span>
&nbsp;
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;https://wwwXXX.v1host.com/yourhostingid/&quot;</span>
<span style="color: #800080;">$username</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;User&quot;</span>
<span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-assecurestring</span> <span style="color: #800000;">&quot;Password&quot;</span>
&nbsp;
<span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.Marshal<span style="color: #000000;">&#93;</span>::PtrToStringAuto<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>System.Runtime.InteropServices.Marshal<span style="color: #000000;">&#93;</span>::SecureStringToBSTR<span style="color: #000000;">&#40;</span><span style="color: #800080;">$password</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$apiClient</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">resolve-path</span> <span style="color: #800000;">&quot;versionone.sdk.apiclient.dll&quot;</span>
<span style="color: #800080;">$objectModel</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">resolve-path</span> <span style="color: #800000;">&quot;versionone.sdk.objectmodel.dll&quot;</span>
<span style="color: #000000;">&#91;</span>Reflection.Assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadFrom</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$apiClient</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #000000;">&#91;</span>Reflection.Assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadFrom</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$objectModel</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #800080;">$v1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> VersionOne.SDK.ObjectModel.V1Instance<span style="color: #000000;">&#40;</span> <span style="color: #800080;">$url</span><span style="color: pink;">,</span> <span style="color: #800080;">$username</span><span style="color: pink;">,</span> <span style="color: #800080;">$password</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$v1</span>.Validate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$sf</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> VersionOne.SDK.ObjectModel.Filters.StoryFilter
<span style="color: #800080;">$v1</span>.Get.Iterations<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.IsActive <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$sf</span>.Iteration.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$v1</span>.Get.Teams<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Name <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$teamName</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$sf</span>.Team.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> 
<span style="color: #800080;">$stories</span> <span style="color: pink;">=</span> <span style="color: #800080;">$v1</span>.Get.Stories<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sf</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$story</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$stories</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$story</span>.Owners<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #800080;">$memberDetail</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 		
			<span style="color: #800080;">$md</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> PSObject <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Email<span style="color: pink;">,</span> DetailEstimate<span style="color: pink;">,</span> ToDo<span style="color: pink;">,</span> Effort<span style="color: pink;">,</span> EffortToday<span style="color: pink;">,</span> DoneWithToDo
			<span style="color: #800080;">$md</span>.Email <span style="color: pink;">=</span> <span style="color: #800080;">$owner</span>.Email;
			<span style="color: #800080;">$md</span>.DetailEstimate <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.ToDo <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.Effort <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.EffortToday <span style="color: pink;">=</span> <span style="color: #000000;">0</span>;
			<span style="color: #800080;">$md</span>.DoneWithToDo <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$memberDetail</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$owner</span>.ID<span style="color: pink;">,</span> <span style="color: #800080;">$md</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.ToDo <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>.ToDo;
		<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.DetailEstimate <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>.DetailEstimate;
&nbsp;
		<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$story</span>.ToDo <span style="color: #FF0000;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$story</span>.Status.CurrentValue <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Done&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.DoneWithToDo <span style="color: pink;">+=</span> <span style="color: #800080;">$story</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$effortRecord</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$story</span>.GetEffortRecords<span style="color: #000000;">&#40;</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.Effort <span style="color: pink;">+=</span> <span style="color: #800080;">$effortRecord</span>.Value;
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$effortRecord</span>.CreateDate <span style="color: #FF0000;">-ge</span> <span style="color: #000000;">&#91;</span>DateTime<span style="color: #000000;">&#93;</span>::Today<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #800080;">$memberDetail</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$owner</span>.ID<span style="color: #000000;">&#93;</span>.EffortToday <span style="color: pink;">+=</span> <span style="color: #800080;">$effortRecord</span>.Value;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailSMTPServer</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span>.Values <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.EffortToday <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.ToDo <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailFrom</span><span style="color: pink;">,</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Email<span style="color: pink;">,</span> <span style="color: #800000;">&quot;V1 Nag: No Points Burned Down Today&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Please make sure you have recorded any effort completed on your stories for the day.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$memberDetail</span>.Values <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.DoneWithToDo.Count <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailFrom</span><span style="color: pink;">,</span> <span style="color: #800080;"><span style="color: #000080;">$_</span></span>.Email<span style="color: pink;">,</span> <span style="color: #800000;">&quot;V1 Nag: Story Marked As Done With ToDo Balance&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Please make sure you have zero'd out ToDo on your Completed/Done stories.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></pre></div></div>

<p>You'll need to download the .NET SDK and build the requisite DLLs from:<br />
<a href="http://community.versionone.com/Downloads/default.aspx">http://community.versionone.com/Downloads/default.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/02/versionone-nag-reminding-us-to-burn-our-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clone Analysis Services Partitions with PowerShell</title>
		<link>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/</link>
		<comments>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 20:45:20 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[amo]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=322</guid>
		<description><![CDATA[Most of us with large Analysis Services cubes partition our cubes by month or year or some other time-based slice and we have all, at one point or another, developed some way to create partitions for new months on-demand. Often, the solution to this seems to be a C# console application or SSIS package using [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us with large Analysis Services cubes partition our cubes by month or year or some other time-based slice and we have all, at one point or another, developed some way to create partitions for new months on-demand.  Often, the solution to this seems to be a C# console application or SSIS package using AMO to create a new partition based off an existing partition.  The problem I see with this is that maintaining it requires opening up the project or package, making changes, re-compiling, deploying, testing, deploying to production, verifying, etc.  It also requires that whoever is going to maintain it is comfortable with C#.</p>
<p>To simplify the maintenance and get rid of the "black box" factor that utility apps like this tend to have, I put together a PowerShell script to do the same thing and a stored procedure to call the script.  Really, it doesn't matter what you use as you're most likely using an almost identical chunk of code to get your new partition created - my argument is that using PowerShell instead of C# or SSIS reduces the cost of maintenance, improves readability, and facilitates better understanding throughout your team.<br />
<span id="more-322"></span><br />
<em>The PowerShell Script: cloneSSASPartition.ps1</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$ServerName</span><span style="color: pink;">,</span> 		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Analysis Services Instance #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$DatabaseName</span><span style="color: pink;">,</span> 		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Database our Cube is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$CubeName</span><span style="color: pink;">,</span>     		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Cube that our Measure Group is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$MeasureGroupName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Measure Group that our Partition is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$SourcePartitionName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Partition we want to merge in to another partition #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$NewPartitionName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The desired name of the new partition #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$NewPartitionQuery</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The Query source for the new partition (will use the same datasource as the SourcePartition #&gt;</span>
<span style="color: #000000;">&#41;</span>
&nbsp;
<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;">&quot;Microsoft.AnalysisServices&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span><span style="color: #800080;">$NULL</span>
&nbsp;
<span style="color: #800080;">$server</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.AnalysisServices.Server
<span style="color: #800080;">$server</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$ServerName</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$database</span> <span style="color: pink;">=</span> <span style="color: #800080;">$server</span>.Databases.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DatabaseName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$cube</span> <span style="color: pink;">=</span> <span style="color: #800080;">$database</span>.Cubes.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CubeName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$measureGroup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$cube</span>.MeasureGroups.FindByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$MeasureGroupName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$sourcePartition</span> <span style="color: pink;">=</span> <span style="color: #800080;">$measureGroup</span>.Partitions.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$SourcePartitionName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$sourceQueryBinding</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sourcePartition</span>.Source
&nbsp;
<span style="color: #800080;">$newPartition</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sourcePartition</span>.Clone<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$newPartition</span>.ID <span style="color: pink;">=</span> <span style="color: #800080;">$NewPartitionName</span>
<span style="color: #800080;">$newPartition</span>.Name <span style="color: pink;">=</span> <span style="color: #800080;">$NewPartitionName</span>
<span style="color: #800080;">$measureGroup</span>.Partitions.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$newPartition</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #800080;">$newPartition</span>.Source <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.AnalysisServices.QueryBinding<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sourceQueryBinding</span>.DataSourceID<span style="color: pink;">,</span> <span style="color: #800080;">$NewPartitionQuery</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$newPartition</span>.Update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$server</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p><em>The stored procedure to call the script: [Utility_CloneSSASPartition_S01] - assumes you placed cloneSSASPartition.ps1 at the root of the C: drive.  If you put it elsewhere, update the proc to reflect the actual location.</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
GO
&nbsp;
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>
GO
&nbsp;
<span style="color: #008080;">/*************************************************************************************
***
*** Procedure:  		[Utility_CloneSSASPartition]
*** Purpose:		Executes PowerShell script to clone a SSAS partition
***			
***			
*** Author:		tl
*** Date Created:		2010-01-15
*** 
*** Revision History
*** Date		Author			Description
*** 2010-01-15	tl			Created
*************************************************************************************/</span>
&nbsp;
<span style="color: #0000FF;">CREATE</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>Utility_CloneSSASPartition_S01<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
	@ServerName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@DatabaseName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@CubeName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@MeasureGroupName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@SourcePartitionName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@NewPartitionName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@NewPartitionQuery <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span> 
&nbsp;
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">DECLARE</span> @cmd <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SET</span> @cmd <span style="color: #808080;">=</span> 
	<span style="color: #FF0000;">'powershell.exe -Command &quot;&amp; {'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' C:<span style="color: #000099; font-weight: bold;">\c</span>loneSSASPartition.ps1'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -ServerName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @ServerName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -DatabaseName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @DatabaseName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -CubeName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @CubeName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -MeasureGroupName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @MeasureGroupName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -SourcePartitionName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @SourcePartitionName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -NewPartitionName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @NewPartitionName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -NewPartitionQuery:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @NewPartitionQuery <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>}&quot;'</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> @cmd
<span style="color: #0000FF;">EXEC</span> xp_cmdshell @cmd</pre></div></div>

<p>And, finally, we execute it</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Utility_CloneSSASPartition_S01<span style="color: #808080;">&#93;</span>
	 @ServerName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TESTSERVER'</span>
	,@DatabaseName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TestDatabase'</span>
	,@CubeName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TestCube'</span>
	,@MeasureGroupName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Measure Group'</span>
	,@SourcePartitionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Partition - 200912'</span>
	,@NewPartitionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Partition - 201001'</span>
	,@NewPartitionQuery <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SELECT * FROM dbo.FactTableMonth('</span><span style="color: #FF0000;">'1/1/2010'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'2/1/2010'</span><span style="color: #FF0000;">')'</span></pre></div></div>

<p>Again, I'm not saying there's anything "wrong" with using C# or SSIS Packages to do this sort of thing, I'm just pointing out that C# isn't always the answer - especially when someone other than you needs to maintain this thing in the future.  Keep it simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trending SQL Server Agent Job Duration by Hour</title>
		<link>http://timlaqua.com/2009/12/trending-sql-server-agent-job-duration-by-hour/</link>
		<comments>http://timlaqua.com/2009/12/trending-sql-server-agent-job-duration-by-hour/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 03:07:38 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[agent job]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server 2008]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=302</guid>
		<description><![CDATA[Earlier today I noticed a SQL Server Agent job taking a little longer than usual (or what I thought was longer than usual). Let's face it, we're not staring at the Job Activity monitor all day, so unless you've written a report to monitor job run times - on occasion you ask yourself "is that [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today I noticed a SQL Server Agent job taking a little longer than usual (or what I thought was longer than usual).  Let's face it, we're not staring at the Job Activity monitor all day, so unless you've written a report to monitor job run times - on occasion you ask yourself "is that a normal run time for this thing?"  The job I was curious about happened to be a job that runs throughout the day and should only have real work to do once or twice an hour - and it should run roughly the same amount of time on any given business day for a given hour (i.e. at 1:00 PM on any given business day, this thing should do the same amount of work).</p>
<p>So I came up with the following query to PIVOT the run duration on the hour the job executed:<span id="more-302"></span></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @JobName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Agent Job Name'</span>
&nbsp;
;WITH JobHistory <span style="color: #0000FF;">AS</span>
<span style="color: #808080;">&#40;</span>
  <span style="color: #0000FF;">SELECT</span>
     a.<span style="color: #202020;">run_date</span>
    ,a.<span style="color: #202020;">run_time</span> <span style="color: #808080;">/</span> <span style="color: #000;">10000</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">HOUR</span><span style="color: #808080;">&#93;</span>
    ,<span style="color: #808080;">&#40;</span>a.<span style="color: #202020;">run_duration</span> <span style="color: #808080;">/</span> <span style="color: #000;">10000</span> <span style="color: #808080;">*</span> <span style="color: #000;">60</span> <span style="color: #808080;">*</span> <span style="color: #000;">60</span>	<span style="color: #008080;">-- Hours</span>
     <span style="color: #808080;">+</span> a.<span style="color: #202020;">run_duration</span> <span style="color: #808080;">%</span> <span style="color: #000;">10000</span> <span style="color: #808080;">/</span> <span style="color: #000;">100</span> <span style="color: #808080;">*</span> <span style="color: #000;">60</span>	<span style="color: #008080;">-- Minutes</span>
     <span style="color: #808080;">+</span> a.<span style="color: #202020;">run_duration</span> <span style="color: #808080;">%</span> <span style="color: #000;">100</span>			<span style="color: #008080;">-- Seconds</span>
     <span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">60.0</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>DurationMinutes<span style="color: #808080;">&#93;</span>
  <span style="color: #0000FF;">FROM</span>
    msdb.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">sysjobhistory</span> a <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
    <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> msdb.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">sysjobs</span> b <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
    <span style="color: #0000FF;">ON</span> 
      a.<span style="color: #808080;">&#91;</span>job_id<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>job_id<span style="color: #808080;">&#93;</span>
      <span style="color: #808080;">AND</span> b.<span style="color: #808080;">&#91;</span>name<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> @JobName
      <span style="color: #808080;">AND</span> step_id <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
      <span style="color: #808080;">AND</span> run_status <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span>
  JobHistory	
  PIVOT
  <span style="color: #808080;">&#40;</span> <span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>DurationMinutes<span style="color: #808080;">&#41;</span>
    <span style="color: #0000FF;">FOR</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">HOUR</span><span style="color: #808080;">&#93;</span> 
    <span style="color: #808080;">IN</span>  <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>00<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>01<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>02<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>03<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>04<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>05<span style="color: #808080;">&#93;</span>
        ,<span style="color: #808080;">&#91;</span>06<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>07<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>08<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span>09<span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">10</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">11</span><span style="color: #808080;">&#93;</span>
        ,<span style="color: #808080;">&#91;</span><span style="color: #000;">12</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">13</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">14</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">15</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">16</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">17</span><span style="color: #808080;">&#93;</span>
        ,<span style="color: #808080;">&#91;</span><span style="color: #000;">18</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">19</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">20</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">21</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">22</span><span style="color: #808080;">&#93;</span>,<span style="color: #808080;">&#91;</span><span style="color: #000;">23</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
  <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> p</pre></div></div>

<p><em>UPDATE: Added <strong>AND run_status = 1</strong></em><br/></p>
<p>Then made a table (not sure why, but I can't resist doing the heatmap thing):<br />
<a href="http://timlaqua.com/wp-content/uploads/2009/12/agentJobDurationTable.png"><img src="http://timlaqua.com/wp-content/uploads/2009/12/agentJobDurationTable-300x52.png" alt="" title="agentJobDurationTable" width="300" height="52" class="alignnone size-medium wp-image-304" /></a><br/><em>click the image to enlarge</em></p>
<p>And, of course, the chart so you can point at a picture should you have to explain something to somebody in the future:<br />
<a href="http://timlaqua.com/wp-content/uploads/2009/12/agentJobDurationChart.png"><img src="http://timlaqua.com/wp-content/uploads/2009/12/agentJobDurationChart-300x146.png" alt="" title="agentJobDurationChart" width="300" height="146" class="alignnone size-medium wp-image-305" /></a><br/><em>click the image to enlarge</em></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/12/trending-sql-server-agent-job-duration-by-hour/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wouldn&#8217;t it be fun if Cubes could talk?</title>
		<link>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/</link>
		<comments>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 19:47:21 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[amo]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[cubes]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=291</guid>
		<description><![CDATA[I didn't say "wouldn't it be useful" because after putting a test together, asking a cube questions with no context tends to return answers that it probably shouldn't have returned. In BI, it is incredibly important to understand what exactly it is you're asking for - if we just say we want "sales" and return [...]]]></description>
			<content:encoded><![CDATA[<p>I didn't say "wouldn't it be useful" because after putting a test together, asking a cube questions with no context tends to return answers that it probably shouldn't have returned.  In BI, it is incredibly important to understand what exactly it is you're asking for - if we just say we want "sales" and return an answer, nobody really knows what we meant by "sales."  Sure, in various circles, "sales" means the same thing - but once you start talking to different areas, departments, etc - the meaning of the word starts to shift.</p>
<p>But I digress - asking cubes questions is still pretty fun and some of the random things it returns when you point it at your own cubes can be flat out hilarious.</p>
<p>Here's a few questions thrown at the Adventure Works cube in the Adventure Works DW 2008 Analysis Services database<br />
<span id="more-291"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">what was sales for nichole nara
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])
$13,295.38
what were sales for nichole nara in cy 2004
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works]))
$2,419.06
what were sales for nichole nara in cy 2004 in north america
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])))
No Results Found
what were sales for nichole nara in cy 2004 for bikes
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Product].[Category].[Bikes]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])))
$2,384.07
what were sales in north america in fy 2003 for bikes
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Product].[Category].[Bikes]} ON 0 FROM (SELECT {[Date].[Fiscal Year].[FY 2003]} ON 0 FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM [Adventure Works])))
$1,739,306.95
sales for cy 2004 in cy q1, cy q2, and cy q4 in north america and canada
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America],[Customer].[Country].[Canada]} ON 0 FROM (SELECT {[Date].[Calendar Quarter of Year].[CY Q1],[Date].[Calendar Quarter of Year].[CY Q2],[Date].[Calendar Quarter of Year].[CY Q4]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM [Adventure Works])))
I don't know - Query Failure: Members belong to different hierarchies in the  function.
sales for cy 2004 in cy q1, cy q2, and cy q4 in north america
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM (SELECT {[Date].[Calendar Quarter of Year].[CY Q1],[Date].[Calendar Quarter of Year].[CY Q2],[Date].[Calendar Quarter of Year].[CY Q4]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM [Adventure Works])))
$3,967,371.16
sales between cy 2003 and cy 2004 for large resellers
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT [Large Resellers] ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2003]:[Date].[Calendar Year].[CY2004]} ON 0 FROM [Adventure Works]))
$19,561,960.04
sales for top 50 customers in fy 2004 in fy q1 and fy q3
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Date].[Fiscal Quarter of Year].[FY Q1],[Date].[Fiscal Quarter of Year].[FY Q3]} ON 0 FROM (SELECT {[Date].[Fiscal Year].[FY 2004]} ON 0 FROM (SELECT [Top 50 Customers] ON 0 FROM [Adventure Works])))
$177,263.41</pre></div></div>

<p>The above questions returned pretty much exactly what I was looking for except for the one that threw us an error about members belonging to different hierarchies.  That one was because "Canada" was in [Customer].[Country] and "north america" was in [Sales Territory].[Sales Territory Group].  Yeah, it was a dumb question because canada is in north america, but it illustrates that when you don't qualify things, you can get some pretty confusing results.</p>
<p><strong>How's it work?</strong></p>
<ol>
<li>Enumerate all the Attribute Values for each Attribute Hierarchy and store them as "keywords"</li>
<li>Get some input</li>
<li>Look for the aforementioned "keywords" in the input string</li>
<li>Construct an MDX query based on what "keywords" were found in the string</li>
<li>Make sure there aren't any extra (non-noise) words in the string</li>
<li>Run Query</li>
<li>Return Results</li>
</ol>
<p><strong>How the queries are constructed</strong></p>
<ul>
<li>Attribute Values just create a subcube - it creates a new nested subcube for each list, range, or named set it finds</li>
<li>It only supports one measure as written and it just selects that from whatever quagmire of subcubes it's created</li>
</ul>
<p>There are tons of issues with this methodology when we have role playing dimensions because the attribute values will be the same for these dimensions - so only the first one enumerated will get in (there's a way to ignore certain dimensions in the app.config - ignore all but one role playing dimension).  It throws away context and calls it "noise" - now that's dangerous;  if you throw away the context and just look for keywords, it's pretty easy to answer a question that wasn't really asked (oops).</p>
<p>As far as configuring this thing goes - take a look at the app.config and throw in appropriate values for your setup.  You'll have to tweak the *Pattern values to fit things you want to match or exclude in your particular cube.  It's configured for the Adventure Works cube right now, but I didn't work with it much - I just flat out excluded a few dims and hierarchies that would obviously confuse it.</p>
<p>Also note that, as written, it needs an Analysis Services 2008 cube.</p>
<p>Let me know if you want to give it a try and I'll be more than happy to work with you on configuring/modifying it for your setup.  Also post comments on interesting observations you have when asking cubes unqualified questions <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href='http://timlaqua.com/wp-content/uploads/2009/11/SmartCube.zip'>Download the VS 2008 Project: SmartCube.zip</a></p>
<p>Also note, the project uses an interface called IODoodad for getting questions and responding - this has two public methods, GetInput() and Respond().  The original theory here is that we could make an old-school IRC bot type thing.  We did manage to hook it to Yammer for its IO, respond to private messages and public messages prefixed with @cube, etc.  I didn't really explain the config for YammerIO (there's a custom config section for that that needs a bunch of OAuth stuff).  Again, if you're interested in getting that working, let me know and I'll post instructions.  The project above is set to use ConsoleIO.</p>
<p>I don't plan on doing any more development here, it was just a quick PoC to see what it looked like and get some initial feedback.  If anyone's interested in moving forward with it and making it smarter (the project arguably should have been titled DumbCube at this point), let me know so I can post a link to your work and fork away <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Charting Analysis Services 2008 Trace Events</title>
		<link>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/</link>
		<comments>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 15:05:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=273</guid>
		<description><![CDATA[The other day I was running some Analysis Services traces for some reason or another and ran across Chris Webb's post on (Visualising Analysis Services Trace Information in Reporting Services). After looking over that post, I thought it'd be interesting to visualize various types of processing, queries, etc - basically take a trace and then [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was running some Analysis Services traces for some reason or another and ran across Chris Webb's post on (<a href="http://cwebbbi.spaces.live.com/Blog/cns!7B84B0F2C239489A!1660.entry">Visualising Analysis Services Trace Information in Reporting Services</a>).  After looking over that post, I thought it'd be interesting to visualize various types of processing, queries, etc - basically take a trace and then graph out what happened and when.  Here's a few samples of what the project yielded:</p>
<ul>
<li style="color: red;">Red: <em>Cube Processing on a 2 Minute schedule</em></li>
<li style="color: green;">Green: <em>Cube Processing on a 1 hour schedule</em></li>
<li style="color: blue;">Blue: <em>Cube Processing on a 1 hour schedule</em></li>
<li style="color: black;">Black: <em>Query Activity</em></li>
</ul>
<p><em>Most of the activity here is from SSRS subscriptions firing around 8AM </em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/8AM-MSRS-Subscription-Processing.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/8AM-MSRS-Subscription-Processing-300x174.png" alt="8AM MSRS Subscription Processing" title="8AM MSRS Subscription Processing" width="300" height="174" class="alignnone size-medium wp-image-269" /></a><br />
<span id="more-273"></span><br />
<em>This is the report filtered to only show events that had a duration greater than 10,000 MS (10 seconds) - Red cube is a trouble maker</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/SSAS-Events-Longer-Than-10-Seconds.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/SSAS-Events-Longer-Than-10-Seconds-300x173.png" alt="SSAS Events Longer Than 10 Seconds" title="SSAS Events Longer Than 10 Seconds" width="300" height="173" class="alignnone size-medium wp-image-270" /></a></p>
<p><em>And this is general SSAS activity over a few hours with the nearly instant events filtered out</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/General-SSAS-Activity-3-Hours.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/General-SSAS-Activity-3-Hours-300x173.png" alt="General SSAS Activity (3 Hours)" title="General SSAS Activity (3 Hours)" width="300" height="173" class="alignnone size-medium wp-image-271" /></a></p>
<p>The following query assumes that the trace data ended up in a table:</p>
<ul>
<li>@StartMillisecond: INT; <em>Minimum relative start time (millisecond value, kinda have to guess and check)</em></li>
<li>@EndMillisecond: INT; <em>Maximum relative start time (millisecond value, kinda have to guess and check)</em></li>
<li>@MinDuration: INT; <em>Minimum duration in milliseconds</em></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">;WITH <span style="color: #66cc66;">&#91;</span>ProcessEvent<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	<span style="color: #ff0000;">'Process'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:DatabaseID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:DimensionID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:MeasureGroupID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>MeasureGroupId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> dbo<span style="color: #66cc66;">.</span>zTrace_MSAS_20091023_2 T
<span style="color: #993333; font-weight: bold;">WHERE</span> 
	T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventClass<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">16</span> 
	<span style="color: #993333; font-weight: bold;">AND</span> T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventSubclass<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Process%'</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>QueryEvent<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	<span style="color: #ff0000;">'Query'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>DatabaseName<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>MeasureGroupId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> dbo<span style="color: #66cc66;">.</span>zTrace_MSAS_20091023_2 T
<span style="color: #993333; font-weight: bold;">WHERE</span> T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventClass<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">10</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>ProcessEvent<span style="color: #66cc66;">&#93;</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>QueryEvent<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	 ROW_NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> OVER <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>EventId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>DATEADD<span style="color: #66cc66;">&#40;</span>HOUR<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#91;</span>RelativeStartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>CASE
		WHEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #ff0000;">'Dimension'</span>
		WHEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #ff0000;">'Measure Group'</span>
		ELSE <span style="color: #ff0000;">'None'</span>
	 END <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>ObjectType<span style="color: #66cc66;">&#93;</span>	<span style="color: #66cc66;">,</span>CASE
		WHEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
		WHEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span>
		ELSE <span style="color: #ff0000;">'None'</span>
	 END <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>ObjectId<span style="color: #66cc66;">&#93;</span>	
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span>
	DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;=</span> @StartMillisecond
	<span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> @EndMillisecond
	<span style="color: #993333; font-weight: bold;">AND</span> Duration <span style="color: #66cc66;">&gt;=</span> @MinDuration</pre></div></div>

<p>A few notes on the report:</p>
<ul>
<li>[EventId] is the Series Group</li>
<li>This is a Range chart type, the Bottom value was [RelativeStartTime] and the Top value was [RelativeStartTime] + [Duration]</li>
<li>Coloring the series and markers uses the following expression

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">=</span>Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span><span style="color: #0600FF;">Event</span>.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Process&quot;</span>
	,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SSASDB&quot;</span>
		,<span style="color: #666666;">&quot;Red&quot;</span>
		,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;OtherSSASDB&quot;</span>
			,<span style="color: #666666;">&quot;Green&quot;</span>
			,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;YetAnotherSSASDB&quot;</span>
				,<span style="color: #666666;">&quot;Blue&quot;</span>
				,<span style="color: #666666;">&quot;Pink&quot;</span>
			<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#41;</span>
	,<span style="color: #666666;">&quot;Black&quot;</span>
<span style="color: #000000;">&#41;</span></pre></div></div>

</li>
</ul>
<p>And that's about it - if you have any more questions about it just let me know.  Just seemed like an interesting way to look at trace data <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   It also wouldn't be that difficult to generate events for other things, like your ETL processing and such so you could see that on top of everything else.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Estimating the Size of a Table in SQL Server 2008</title>
		<link>http://timlaqua.com/2009/10/estimating-the-size-of-a-table-in-sql-server-2008/</link>
		<comments>http://timlaqua.com/2009/10/estimating-the-size-of-a-table-in-sql-server-2008/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 02:35:00 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[msdn]]></category>
		<category><![CDATA[mssql 2008]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=250</guid>
		<description><![CDATA[I have read this (http://msdn.microsoft.com/en-us/library/ms178085.aspx) article at least 6, maybe 7 times in the past - and every time I say to myself "this is ridiculous - someone has to have written a script to do this by now" and every time, I google for hours and fail to find anything. So I finally gave [...]]]></description>
			<content:encoded><![CDATA[<p>I have read this (<a href="http://msdn.microsoft.com/en-us/library/ms178085.aspx">http://msdn.microsoft.com/en-us/library/ms178085.aspx</a>) article at least 6, maybe 7 times in the past - and every time I say to myself "this is ridiculous - someone has to have written a script to do this by now" and every time, I google for hours and fail to find anything.  So I finally gave up and wrote something to do it.  Note, I've only verified it on 100% fixed width tables.  I compared its output to a 600+ million row table and it came out somewhere around 3% higher - fine with me as I'd rather over-estimate space requirements than under-estimate.<br />
<span id="more-250"></span><br />
First, we have to create a table type to hold our table column definitions.  the datatype is required, length is required for anything that allows length (MAX is not handled for any types), and the worst case scenario is always used so if you know you won't be filling those VARCHAR(255)s, feel free to use a smaller, more average, number.  IsKey is a BIT value that tells the proc to use those columns as part of the index key.  The rest of it is all calculated.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> TYPE TableColumnDefinition <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>
	,<span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span>
	,<span style="color: #808080;">&#91;</span>IsKey<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">BIT</span>
	,<span style="color: #808080;">&#91;</span>DataLength<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span>
		<span style="color: #0000FF;">CASE</span> 
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'BIT'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">0.125</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TINYINT'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SMALLINT'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">2</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #FF0000;">'SMALLMONEY'</span>, <span style="color: #FF0000;">'REAL'</span>, <span style="color: #FF0000;">'SMALLDATETIME'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">4</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'BIGINT'</span>, <span style="color: #FF0000;">'DATETIME'</span>, <span style="color: #FF0000;">'MONEY'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'UNIQUEIDENTIFIER'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">16</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'NVARCHAR'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">*</span> <span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #000;">2</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'VARCHAR'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">+</span> <span style="color: #000;">2</span>	<span style="color: #008080;">-- DOESN'T SUPPORT MAX</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Datatype<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DATE'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">3</span> 
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Datatype<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TIME'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">5</span> <span style="color: #008080;">-- Worst case</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Datatype<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DATETIME2'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span> <span style="color: #008080;">-- Worst case</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Datatype<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DATETIMEOFFSET'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">10</span> <span style="color: #008080;">-- Worst case</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'CHAR'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'NCHAR'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">*</span> <span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #000;">2</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'BINARY'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'VARBINARY'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">+</span> <span style="color: #000;">2</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Datatype<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TIMESTAMP'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'XML'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span>	<span style="color: #008080;">-- Estimate an average size in bytes, 2GB max</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'DECIMAL'</span>, <span style="color: #FF0000;">'NUMERIC'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> 
				<span style="color: #0000FF;">CASE</span> 
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">1</span> <span style="color: #808080;">AND</span> <span style="color: #000;">9</span>	<span style="color: #0000FF;">THEN</span> <span style="color: #000;">5</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">10</span> <span style="color: #808080;">AND</span> <span style="color: #000;">19</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">9</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">20</span> <span style="color: #808080;">AND</span> <span style="color: #000;">28</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">13</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">29</span> <span style="color: #808080;">AND</span> <span style="color: #000;">38</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">17</span>
				<span style="color: #0000FF;">END</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'FLOAT'</span> <span style="color: #0000FF;">THEN</span>
				<span style="color: #0000FF;">CASE</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">1</span> <span style="color: #808080;">AND</span> <span style="color: #000;">24</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">4</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">25</span> <span style="color: #808080;">AND</span> <span style="color: #000;">53</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>Length<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>	<span style="color: #008080;">-- Default n is 53</span>
				<span style="color: #0000FF;">END</span>
			<span style="color: #0000FF;">ELSE</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">END</span>
	,<span style="color: #808080;">&#91;</span>IsVariableLength<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span>
		<span style="color: #0000FF;">CASE</span> 
			<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span>DataType<span style="color: #808080;">&#93;</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'VARCHAR'</span>, <span style="color: #FF0000;">'NVARCHAR'</span>, <span style="color: #FF0000;">'VARBINARY'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span>
			<span style="color: #0000FF;">ELSE</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">END</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>Now for the proc that attempts to replicate the methodology outlined on the aforementioned MSDN article.  The results appeared to be accurate or over the actual value, which was exactly what I needed, so I went with it and moved on.  I'm completely open to corrections, suggestions, improvements, etc.  Just make a comment and I'll integrate them (assuming they work <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">/*************************************************************************************
***
*** Procedure:  		[Utility_EstimateClusteredIndexSize]
*** Purpose:		    Estimates the amount of space needed for a given clustered index
*** Methodology:		http://msdn.microsoft.com/en-us/library/ms178085.aspx
***			
***			
*** Author:		      Tim Laqua
*** Date Created:	  2009-10-15 
*** 
*** Revision History
*** Date		Author			Description
*** 2009-10-15	tl				Created
*************************************************************************************/</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>Utility_EstimateClusteredIndexSize<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
	 @Num_Rows <span style="color: #0000FF;">FLOAT</span>
	,@ClusteredIndexIsUnique <span style="color: #0000FF;">BIT</span>
	,@Fill_Factor <span style="color: #0000FF;">FLOAT</span>
	,@TableColumn TableColumnDefinition READONLY
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span> 
&nbsp;
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span>
	 @Num_Cols <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>					<span style="color: #008080;">-- total number of columns (fixed-length and variable-length)</span>
	,@Fixed_Data_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>			<span style="color: #008080;">-- total byte size of all fixed-length columns</span>
	,@Num_Variable_Cols <span style="color: #0000FF;">FLOAT</span>	<span style="color: #808080;">=</span> <span style="color: #000;">0</span>			<span style="color: #008080;">-- number of variable-length columns</span>
	,@Max_Var_Size <span style="color: #0000FF;">FLOAT</span>	<span style="color: #808080;">=</span> <span style="color: #000;">0</span>				<span style="color: #008080;">-- maximum byte size of all variable-length columns</span>
	,@Variable_Data_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">TABLE</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">FLOAT</span>
	,<span style="color: #808080;">&#91;</span>DisplayValue<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span>
		<span style="color: #0000FF;">CASE</span>
			<span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">LOWER</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%size%'</span> <span style="color: #808080;">OR</span> <span style="color: #FF00FF;">LOWER</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>Name<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%space%'</span> <span style="color: #0000FF;">THEN</span>
				<span style="color: #0000FF;">CASE</span> 
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&lt;</span> <span style="color: #000;">1024</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">ROUND</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span>,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' B'</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&lt;</span> <span style="color: #000;">1024</span><span style="color: #808080;">*</span><span style="color: #000;">1024</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">ROUND</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span>,<span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' KB'</span>
					<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&lt;</span> <span style="color: #000;">1024</span><span style="color: #808080;">*</span><span style="color: #000;">1024</span><span style="color: #808080;">*</span><span style="color: #000;">1024</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">ROUND</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span>,<span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' MB'</span>
					<span style="color: #0000FF;">ELSE</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">ROUND</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span><span style="color: #808080;">/</span><span style="color: #000;">1024</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">NUMERIC</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span>,<span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' GB'</span>
				<span style="color: #0000FF;">END</span>
			<span style="color: #0000FF;">ELSE</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">FLOOR</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span><span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #0000FF;">END</span><span style="color: #808080;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #008080;">-- Leaf level data</span>
<span style="color: #0000FF;">SELECT</span> 
	 @Num_Variable_Cols <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
	,@Max_Var_Size <span style="color: #808080;">=</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>DataLength<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> @TableColumn <span style="color: #0000FF;">WHERE</span> <span style="color: #808080;">&#91;</span>IsVariableLength<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> 
	 @Num_Cols <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> @Num_Variable_Cols
	,@Fixed_Data_Size <span style="color: #808080;">=</span> <span style="color: #FF00FF;">CEILING</span><span style="color: #808080;">&#40;</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>DataLength<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> @TableColumn <span style="color: #0000FF;">WHERE</span> <span style="color: #808080;">&#91;</span>IsVariableLength<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Fixed_Data_Size'</span>, @Fixed_Data_Size<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @ClusteredIndexIsUnique <span style="color: #808080;">&lt;&gt;</span> <span style="color: #000;">0</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SET</span> @Num_Cols <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
	<span style="color: #0000FF;">IF</span> @Num_Variable_Cols <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">SET</span> @Num_Variable_Cols <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
	<span style="color: #0000FF;">IF</span> @Max_Var_Size <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">SET</span> @Max_Var_Size <span style="color: #808080;">+=</span> <span style="color: #000;">4</span>
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Null_Bitmap <span style="color: #0000FF;">INT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">CEILING</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>@Num_Cols <span style="color: #808080;">+</span> <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Null_Bitmap'</span>, @Null_Bitmap<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- if there are variable columns</span>
<span style="color: #0000FF;">IF</span> @Num_Variable_Cols <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
	<span style="color: #0000FF;">SET</span> @Variable_Data_Size <span style="color: #808080;">=</span> <span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #808080;">&#40;</span>@Num_Variable_Cols <span style="color: #808080;">*</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> @Max_Var_Size 
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Cols'</span>, @Num_Cols<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Variable_Cols'</span>, @Num_Variable_Cols<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Max_Var_Size'</span>, @Max_Var_Size<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Row_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">CEILING</span><span style="color: #808080;">&#40;</span>@Fixed_Data_Size <span style="color: #808080;">+</span> @Variable_Data_Size <span style="color: #808080;">+</span> @Null_Bitmap <span style="color: #808080;">+</span> <span style="color: #000;">4</span> <span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Row_Size'</span>, @Row_Size<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Rows_Per_Page <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">FLOOR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8096</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>@Row_Size <span style="color: #808080;">+</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Rows_Per_Page'</span>, @Rows_Per_Page<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Free_Rows_Per_Page <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">FLOOR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8096</span> <span style="color: #808080;">*</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span> <span style="color: #808080;">-</span> @Fill_Factor<span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">100</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>@Row_Size <span style="color: #808080;">+</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Free_Rows_Per_Page'</span>, @Free_Rows_Per_Page<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Num_Leaf_Pages <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">CEILING</span><span style="color: #808080;">&#40;</span>@Num_Rows <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>@Rows_Per_Page <span style="color: #808080;">-</span> @Free_Rows_Per_Page<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Leaf_Pages'</span>, @Num_Leaf_Pages<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Leaf_space_used <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">8192</span> <span style="color: #808080;">*</span> @Num_Leaf_Pages
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Leaf_space_used'</span>, @Leaf_space_used<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- Index Information</span>
<span style="color: #0000FF;">DECLARE</span>
	 @Num_Key_Cols <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>			<span style="color: #008080;">-- total number of key columns (fixed-length and variable-length)</span>
	,@Fixed_Key_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>			<span style="color: #008080;">-- total byte size of all fixed-length key columns</span>
	,@Num_Variable_Key_Cols <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>	<span style="color: #008080;">-- number of variable-length key columns</span>
	,@Max_Var_Key_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>		<span style="color: #008080;">-- maximum byte size of all variable-length key columns</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">SELECT</span> 
	 @Num_Variable_Key_Cols <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
	,@Max_Var_Key_Size <span style="color: #808080;">=</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>DataLength<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> @TableColumn 
<span style="color: #0000FF;">WHERE</span> 
	<span style="color: #808080;">&#91;</span>IsVariableLength<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span> 
	<span style="color: #808080;">AND</span> <span style="color: #808080;">&#91;</span>IsKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> 
	 @Num_Key_Cols <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> @Num_Variable_Key_Cols
	,@Fixed_Key_Size <span style="color: #808080;">=</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>DataLength<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> @TableColumn 
<span style="color: #0000FF;">WHERE</span> 
	<span style="color: #808080;">&#91;</span>IsVariableLength<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
	<span style="color: #808080;">AND</span> <span style="color: #808080;">&#91;</span>IsKey<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @ClusteredIndexIsUnique <span style="color: #808080;">&lt;&gt;</span> <span style="color: #000;">0</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SET</span> @Num_Key_Cols <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
	<span style="color: #0000FF;">IF</span> @Num_Variable_Key_Cols <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">SET</span> @Num_Variable_Key_Cols <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
	<span style="color: #0000FF;">IF</span> @Max_Var_Key_Size <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
		<span style="color: #0000FF;">SET</span> @Max_Var_Key_Size <span style="color: #808080;">+=</span> <span style="color: #000;">4</span>
<span style="color: #0000FF;">END</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Variable_Key_Cols'</span>, @Num_Variable_Key_Cols<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Max_Var_Key_Size'</span>, @Max_Var_Key_Size<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Key_Cols'</span>, @Num_Key_Cols<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- Who would seriously have a nullable key column?  ridiculous.</span>
<span style="color: #0000FF;">DECLARE</span> @Index_Null_Bitmap <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>@Num_Key_Cols <span style="color: #808080;">+</span> <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span> 
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Index_Null_Bitmap'</span>, @Index_Null_Bitmap<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Variable_Key_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
&nbsp;
<span style="color: #0000FF;">IF</span> @Max_Var_Key_Size <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
	<span style="color: #0000FF;">SET</span> @Variable_Key_Size <span style="color: #808080;">=</span> <span style="color: #000;">2</span> <span style="color: #808080;">+</span> <span style="color: #808080;">&#40;</span>@Num_Variable_Key_Cols <span style="color: #808080;">*</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> @Max_Var_Key_Size 
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Variable_Key_Size'</span>, @Variable_Key_Size<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Index_Row_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> @Fixed_Key_Size <span style="color: #808080;">+</span> @Variable_Key_Size <span style="color: #808080;">+</span> @Index_Null_Bitmap <span style="color: #808080;">+</span> <span style="color: #000;">1</span> <span style="color: #808080;">+</span> <span style="color: #000;">6</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Index_Row_Size'</span>,@Index_Row_Size <span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Index_Rows_Per_Page  <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">FLOOR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8096</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>@Index_Row_Size <span style="color: #808080;">+</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Index_Rows_Per_Page'</span>, @Index_Rows_Per_Page<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Non_Leaf_Levels <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
&nbsp;
<span style="color: #008080;">-- Log base @Non_Leaf_Levels hack</span>
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span>@Num_Leaf_Pages <span style="color: #808080;">/</span> @Index_Rows_Per_Page<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #FF00FF;">POWER</span><span style="color: #808080;">&#40;</span>@Index_Rows_Per_Page,@Non_Leaf_Levels<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">SET</span> @Non_Leaf_Levels <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
&nbsp;
<span style="color: #0000FF;">SET</span> @Non_Leaf_Levels <span style="color: #808080;">+=</span> <span style="color: #000;">1</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Non_Leaf_Levels'</span>, @Non_Leaf_Levels<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- Summation hack</span>
<span style="color: #0000FF;">DECLARE</span> 
	 @Num_Index_Pages <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
	,@Summand <span style="color: #0000FF;">INT</span> <span style="color: #808080;">=</span> @Non_Leaf_Levels
&nbsp;
<span style="color: #0000FF;">WHILE</span> @Summand <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SET</span> @Num_Index_Pages <span style="color: #808080;">+=</span> <span style="color: #FF00FF;">CEILING</span><span style="color: #808080;">&#40;</span>@Num_Leaf_Pages<span style="color: #808080;">/</span><span style="color: #FF00FF;">POWER</span><span style="color: #808080;">&#40;</span>@Index_Rows_Per_Page, @Summand<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">SET</span> @Summand <span style="color: #808080;">-=</span> <span style="color: #000;">1</span>
<span style="color: #0000FF;">END</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Num_Index_Pages'</span>, @Num_Index_Pages<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Index_Space_Used <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> <span style="color: #000;">8192</span> <span style="color: #808080;">*</span> @Num_Index_Pages 
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Index_Space_Used'</span>, @Index_Space_Used<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @Clustered_Index_Size <span style="color: #0000FF;">FLOAT</span> <span style="color: #808080;">=</span> @Leaf_Space_Used <span style="color: #808080;">+</span> @Index_Space_used
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @<span style="color: #FF00FF;">VAR</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@Clustered_Index_Size'</span>, @Clustered_Index_Size<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> @<span style="color: #FF00FF;">VAR</span></pre></div></div>

<p>Now for an example of how to run this doodad.  This particular estimate was for a staging table - I needed the UNIQUEIDENTIFER as the key and the CreatedTime field had to be part of the clustered index for the partition scheme.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DECLARE</span> @TableColumn TableColumnDefinition
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @TableColumn
<span style="color: #0000FF;">VALUES</span> 
	 <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'UNIQUEIDENTIFIER'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'DATETIME'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	,<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'INT'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Utility_EstimateClusteredIndexSize<span style="color: #808080;">&#93;</span>	
 @Num_Rows <span style="color: #808080;">=</span> <span style="color: #000;">750000</span>		<span style="color: #008080;">-- number of rows in the table</span>
,@ClusteredIndexIsUnique <span style="color: #808080;">=</span> <span style="color: #000;">1</span> 	<span style="color: #008080;">-- is it?</span>
,@Fill_Factor <span style="color: #808080;">=</span> <span style="color: #000;">90</span>			<span style="color: #008080;">-- page fill factor</span>
,@TableColumn <span style="color: #808080;">=</span> @TableColumn	<span style="color: #008080;">-- definition of table columns</span></pre></div></div>

<p>As for what the output looks like, I wanted it to output all the variables used so I could validate along the way with th emanual method.  The results look something like this</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Name                                                             Value                  DisplayValue
---------------------------------------------------------------- ---------------------- -------------------
@Fixed_Data_Size                                                 60                     60 B
@Null_Bitmap                                                     5                      5
@Num_Cols                                                        12                     12
@Num_Variable_Cols                                               0                      0
@Max_Var_Size                                                    0                      0 B
@Row_Size                                                        69                     69 B
@Rows_Per_Page                                                   114                    114
@Free_Rows_Per_Page                                              11                     11
@Num_Leaf_Pages                                                  7282                   7282
@Leaf_space_used                                                 59654144               56.891 MB
@Num_Variable_Key_Cols                                           0                      0
@Max_Var_Key_Size                                                0                      0 B
@Num_Key_Cols                                                    3                      3
@Index_Null_Bitmap                                               3.25                   3
@Variable_Key_Size                                               0                      0 B
@Index_Row_Size                                                  34.25                  34 B
@Index_Rows_Per_Page                                             223                    223
@Non_Leaf_Levels                                                 2                      2
@Num_Index_Pages                                                 34                     34
@Index_Space_Used                                                278528                 272.000 KB
@Clustered_Index_Size                                            59932672               57.156 MB</pre></div></div>

<p>So now you may ask "but what about estimating Non-Clustered Indexes and Heaps?"  Well, good question as this is the methodology for estimating the size of a Clustered Index.  I ran this for a fact table with two non-clustered indexes in addition to the clustered index by basically defining the index (so pretending the index was a table for the purposes of this proc - included columns would just be non-key columns).  All in all, it came out +3.31% on 600+ million rows, so I called that methodology good enough <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/10/estimating-the-size-of-a-table-in-sql-server-2008/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 6.365 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-31 00:10:06 -->
