<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Adventures In SQL</title>
	
	<link>http://adventuresinsql.com</link>
	<description>Random thoughts, rants, discoveries and things I wish I had done better</description>
	<lastBuildDate>Thu, 24 Jan 2013 18:04:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AdventuresInSql" /><feedburner:info uri="adventuresinsql" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/3.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by/3.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>AdventuresInSql</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>What Did that Geek Just Say?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/6BtoSr4biPQ/</link>
		<comments>http://adventuresinsql.com/2010/09/what-did-that-geek-just-say/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 15:00:36 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[DADS]]></category>
		<category><![CDATA[NIST]]></category>
		<category><![CDATA[SSC]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=511</guid>
		<description><![CDATA[The National Institute of Standards and Technology, NIST, maintains a <a href="http://www.itl.nist.gov/div897/sqg/dads/">Dictionary of Algorithms and Data Structures</a>. The dictionary is a great place to go to find out what people are talking about. It is also a great place to looking for different ways of doing things. I sometimes even go to the site just to look for entertaining technical concepts, like the "Cactus Stack", "Stooge Sort" or even "Big-O Notation". <a href="http://adventuresinsql.com/2010/09/what-did-that-geek-just-say/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Working in a technical field has it&#8217;s ups and downs. One of the more common annoyances I run into is people that can either not explain what they mean in simple terms or that choose not to in order to appear knowledgeable. I still have a long way to go before I can suggest a sure-fire approach to curtailing this behavior. Quite honestly, I have been known to fall back on &#8220;fancy tech words&#8221; on more than one occasion to hide ignorance or to try to seem smart (OK that was hiding ignorance twice but it sounds better the way I said it). What I can offer is a great resource to understand what people are saying and maybe even have some fun with them/me.</p>
<p>The National Institute of Standards and Technology, NIST, maintains a <a href="http://www.itl.nist.gov/div897/sqg/dads/">Dictionary of Algorithms and Data Structures</a>. The dictionary is a great place to go to find out what people are talking about. It is also a great place to looking for different ways of doing things. I sometimes even go to the site just to look for entertaining technical concepts, like the &#8220;Cactus Stack&#8221;, &#8220;Stooge Sort&#8221; or even &#8220;Big-O Notation&#8221;.</p>
<p>Have fun with the big words but please only use them for good or at least funny evil. Go ahead and post any you feel are interesting or just plain funny in the comments of this post. The more time I spend on that site the more terms I find I was overlooking.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=6BtoSr4biPQ:YS4JCDzP2f0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=6BtoSr4biPQ:YS4JCDzP2f0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=6BtoSr4biPQ:YS4JCDzP2f0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=6BtoSr4biPQ:YS4JCDzP2f0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=6BtoSr4biPQ:YS4JCDzP2f0:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/6BtoSr4biPQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/09/what-did-that-geek-just-say/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/09/what-did-that-geek-just-say/</feedburner:origLink></item>
		<item>
		<title>How is Fill Factor Impacting My Indexes?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/fcMbYIskq5k/</link>
		<comments>http://adventuresinsql.com/2010/09/how-is-fill-factor-impacting-my-indexes/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 14:00:36 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[fill factor]]></category>
		<category><![CDATA[fill_factor]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[SQL 2008]]></category>
		<category><![CDATA[SQL 2008 R2]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSP]]></category>
		<category><![CDATA[sys.dm_db_index_physical_stats]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=472</guid>
		<description><![CDATA[The theme for this month's T-SQL Tuesday is indexes so it seemed like the perfect excuse to blog about a script that I have written to see what choices for fill factors on indexes actually does to the structure of those indexes. <a href="http://adventuresinsql.com/2010/09/how-is-fill-factor-impacting-my-indexes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://michaeljswart.com/?p=844"><img src="http://adventuresinsql.com/wp-content/uploads/2010/09/TSQL2sDay150x150.jpg" alt="TSQLTuesday Logo" align="right"/></a>The theme for this month&#8217;s T-SQL Tuesday is indexes so it seemed like the perfect excuse to blog about a script that I have written to see what choices for fill factors on indexes actually does to the structure of those indexes. I have to give special thanks to Brent Ozar (<a href="http://www.brentozar.com/">Blog</a>|<a href="http://twitter.com/brento">Twitter</a>) for taking the time to review and offer his thoughts on the query. I have to admit that I was nervous to publish the script because I have not seen anything else like it and figured there must have been a reason for that.</p>
<p>For those that are unfamiliar, fill factor is an optional parameter that can be specified when adding or rebuilding an index. Specifying a fill factor tells SQL Server to leave a certain percentage of each data page open for future inserts in order to lessen the likelihood of page splits. Page splits are what happens when SQL Server tries to add another row to a data page that it does not fit on. Most page splits involve taking half the rows on the page and putting them onto a newly allocated page somewhere else on your data file, allowing sufficient room for the new row to be added to either page. If you are lucky enough that the row you are adding would be the last row on the page then the existing page is left as is and the new row is added to the newly allocated page. Regardless of how the page splits, the new page is almost never anywhere near the other pages of the index it goes with. The scattering of index pages means that the disk heads have to move around a lot more leading to poor performance.</p>
<p>Now that we have talked about the problems that fill factor can help us with, we should talk about the dark side. Yes, the dark side. Setting the fill factor to anything other than the default decreases the rows per page for that index, thereby increasing the number of pages that must be read. According to <a href="http://msdn.microsoft.com/en-us/library/ms177459.aspx">Books Online</a>, the read performance penalty is twice the chosen fill factor. This means that setting the fill factor to 50% will lead to twice as many reads to get the same data. Even a more reasonable number like 90% would have a 20% performance penalty on all reads. </p>
<p>By now it should be clear that choosing the right fill factor for your indexes is one of the more important steps in creating an index, right behind picking the right key columns. The problem is knowing how to pick a good number and here is where it gets tough because like everything else: It Depends and It Changes. My method of setting fill factors is to calculate the rows per page of an index then use the expected change in rows between reindex operations to figure out what percentage of rows need to be left free per page. The exception to this process is if the index is on an ever increasing value, like an identity column, then the fill factor is automatically 100. </p>
<p>My process works very well for the &#8220;It Depends&#8221; part of setting a fill factor but completely ignores the &#8220;It Changes&#8221; part. Over time as tables get larger, the fill factor setting on a table needs to be adjusted down. I have also run into servers where the default fill factor has been set to a value other than 0 (same as 100%), creating a need to quickly identify indexes that could perform better. What I needed was a simple query that I could run that would very quickly give me an idea of where I can adjust fill factors to improve performance.</p>
<p>Here is that query:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>ips.<span style="color: #FF00FF;">object_id</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> table_name,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ips.<span style="color: #202020;">index_type_desc</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>i.<span style="color: #202020;">name</span>, ips.<span style="color: #202020;">index_type_desc</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> index_name,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">RTRIM</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span> &nbsp;<span style="color: #0000FF;">SELECT</span> &nbsp; &nbsp; &nbsp;c.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> c.<span style="color: #202020;">is_identity</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">' (IDENTITY)'</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> ic.<span style="color: #202020;">is_descending_key</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">' &nbsp;'</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">' DESC &nbsp;'</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">index_columns</span> ic<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> sys.<span style="color: #202020;">columns</span> c<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> ic.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> c.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ic.<span style="color: #202020;">column_id</span> <span style="color: #808080;">=</span> c.<span style="color: #202020;">column_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; ic.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> ips.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ic.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> ips.<span style="color: #202020;">index_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ic.<span style="color: #202020;">is_included_column</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> &nbsp; &nbsp;ic.<span style="color: #202020;">key_ordinal</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">' &nbsp;'</span>, <span style="color: #FF0000;">', '</span><span style="color: #808080;">&#41;</span>, ips.<span style="color: #202020;">index_type_desc</span><span style="color: #808080;">&#41;</span> &nbsp;<span style="color: #0000FF;">AS</span> index_keys,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ips.<span style="color: #202020;">record_count</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">page_count</span> <span style="color: #808080;">/</span> <span style="color: #000;">128.0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> space_used_in_MB,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ips.<span style="color: #202020;">avg_page_space_used_in_percent</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> i.<span style="color: #202020;">fill_factor</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">100</span> <span style="color: #0000FF;">ELSE</span> i.<span style="color: #202020;">fill_factor</span> <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> fill_factor,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000;">8096</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">max_record_size_in_bytes</span> <span style="color: #808080;">+</span> <span style="color: #000;">2.00</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> min_rows_per_page,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000;">8096</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">avg_record_size_in_bytes</span> <span style="color: #808080;">+</span> <span style="color: #000;">2.00</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> avg_rows_per_page,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000;">8096</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">min_record_size_in_bytes</span> <span style="color: #808080;">+</span> <span style="color: #000;">2.00</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> max_rows_per_page,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> i.<span style="color: #202020;">fill_factor</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">100.00</span> <span style="color: #0000FF;">ELSE</span> i.<span style="color: #202020;">fill_factor</span> <span style="color: #0000FF;">END</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">100.00</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">avg_record_size_in_bytes</span> <span style="color: #808080;">+</span> <span style="color: #000;">2.0000</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> defined_free_rows_per_page,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <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> ips.<span style="color: #202020;">avg_page_space_used_in_percent</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">100.00</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">avg_record_size_in_bytes</span> <span style="color: #808080;">+</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> actual_free_rows_per_page,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">reads</span> <span style="color: #808080;">=</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_seeks</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_scans</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_lookups</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writes <span style="color: #808080;">=</span> &nbsp;IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_updates</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000;">1.00</span> <span style="color: #808080;">*</span> <span style="color: #808080;">&#40;</span>IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_seeks</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_scans</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span>ius.<span style="color: #202020;">user_lookups</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> ius.<span style="color: #202020;">user_updates</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> ius.<span style="color: #202020;">user_updates</span> <span style="color: #0000FF;">END</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> reads_per_write<br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">dm_db_index_physical_stats</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;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #FF0000;">'SAMPLED'</span><span style="color: #808080;">&#41;</span> ips<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> sys.<span style="color: #202020;">indexes</span> i <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> ips.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> i.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ips.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> i.<span style="color: #202020;">index_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">OUTER</span> <span style="color: #808080;">JOIN</span> sys.<span style="color: #202020;">dm_db_index_usage_stats</span> ius<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> ius.<span style="color: #202020;">database_id</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ips.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> ius.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> ips.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> ius.<span style="color: #202020;">index_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; ips.<span style="color: #202020;">alloc_unit_type_desc</span> <span style="color: #808080;">!=</span> <span style="color: #FF0000;">'LOB_DATA'</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> &nbsp; &nbsp;ips.<span style="color: #202020;">index_type_desc</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>ips.<span style="color: #FF00FF;">object_id</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span>ips.<span style="color: #202020;">page_count</span> <span style="color: #808080;">/</span> <span style="color: #000;">128.0</span><span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>The query should be very familiar to anyone that has looked at index fragmentation in SQL 2005 or newer. The same rules apply, the only difference is the columns that are being used. For larger databases consider limiting the scan to a single table or even a single index. It is also a good idea to ignore smaller tables here. I leave it up to the individual running the script to define a small table. For some that will be 100 pages, others 500 pages, but anything over 1000 pages should probably be looked at. </p>
<p>The size calculations used in the query are based on the formulas found here: <a href="http://msdn.microsoft.com/en-us/library/ms178085(SQL.90).aspx">http://msdn.microsoft.com/en-us/library/ms178085(SQL.90).aspx</a>, although the math is quite simple because the DMV accounts for things like null bitmaps and row version information.</p>
<p>I assume that everyone will come up with slightly different ways to use the query. I like to make 2 passes over the data, the first in the morning and the second after the end of the business day. My first pass through the results is used to look for indexes that have too small of a fill factor set. They are easy to find because their free rows per page numbers are less than 1. A value of less than 1 means that the fill factor either needs to be changed to allow some free rows per page or to be more honest about the actual number of free rows per page. My second pass is used to look at the change over the course of the day. The best way to do the comparison is to paste both result sets into Excel and use formulas to look for differences. The second pass will show the indexes that have their factor set either too high or too low. The idea is to focus just as much on the indexes that show significant changes as much as those that do not show any changes at all.</p>
<p>So there it is, a query to tell how good the current fill factor settings are. </p>
<p>To make sure that all users stay as happy as possible it is best to run the query the first time during an off-peak time so that impact can be safely gauged.</p>
<p>Please let me know if you run into any issues, have any ideas that would make this script better or just want to share how you are using it. As always scripts from the internet are like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=fcMbYIskq5k:AscwyOgOB_o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=fcMbYIskq5k:AscwyOgOB_o:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=fcMbYIskq5k:AscwyOgOB_o:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=fcMbYIskq5k:AscwyOgOB_o:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=fcMbYIskq5k:AscwyOgOB_o:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/fcMbYIskq5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/09/how-is-fill-factor-impacting-my-indexes/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/09/how-is-fill-factor-impacting-my-indexes/</feedburner:origLink></item>
		<item>
		<title>Quote of the Day</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/dg9eylRtPH4/</link>
		<comments>http://adventuresinsql.com/2010/09/quote-of-the-day/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 17:16:20 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[SSC]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=464</guid>
		<description><![CDATA[Today is the first day of the rest of your life. Make it yours, own the day. Repeat tomorrow. This has been your wake up call. <a href="http://adventuresinsql.com/2010/09/quote-of-the-day/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I do not usually post a quote of the day but since this is my own quote I decided to share it.</p>
<blockquote><p>Today is the first day of the rest of your life. Make it yours, own the day. Repeat tomorrow. This has been your wake up call.</p></blockquote>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=dg9eylRtPH4:O-LdPUxYXKg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=dg9eylRtPH4:O-LdPUxYXKg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=dg9eylRtPH4:O-LdPUxYXKg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=dg9eylRtPH4:O-LdPUxYXKg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=dg9eylRtPH4:O-LdPUxYXKg:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/dg9eylRtPH4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/09/quote-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/09/quote-of-the-day/</feedburner:origLink></item>
		<item>
		<title>A Stored Procedure to Move SSIS Packages Between Servers</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/ife5FfJ0rfM/</link>
		<comments>http://adventuresinsql.com/2010/09/a-stored-procedure-to-move-ssis-packages-between-servers/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 15:25:45 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=444</guid>
		<description><![CDATA[This post provides the code for a stored procedure to move SSIS packages between SQL 2005 SSIS servers. <a href="http://adventuresinsql.com/2010/09/a-stored-procedure-to-move-ssis-packages-between-servers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Today&#8217;s post is one that I have been debating on whether to publish for a while. The purpose of the stored procedure I am sharing is to move SSIS packages stored via SQL Server Storage from one server SQL 2005 server to another in a way that can easily be invoked by any release management system that can call stored procedures. The part I have reservations about is that it uses linked servers. I almost never allow linked servers to be created on the servers I manage, mostly because they can be a security problem. Breaking the rules in this case is what was right for the particular problems I was trying to solve. Please consider whether you can implement this logic another way before using this stored procedure in your environment.</p>
<p>This stored procedure is not terribly complicated so I will run through what it does fairly quickly. The first step is to get the folder_id of the package we want to copy. If it gets more than 1 folder name back it throws an error because it does not know which package to move. If the folder_id returned is null then an error is thrown. If the stored procedure makes it through those checks, the current version a the destination is deleted and the new version is copied there.</p>
<p>Here is the code:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> dbo.<span style="color: #202020;">move_ssis_package</span> @from_server_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span>, @to_server_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span>, @package_name sysname<br />
<br />
<span style="color: #0000FF;">AS</span><br />
<br />
<span style="color: #0000FF;">DECLARE</span> @sql_command <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span>,<br />
@folder_id <span style="color: #0000FF;">uniqueidentifier</span>,<br />
@foldername sysname<br />
<br />
<span style="color: #0000FF;">SELECT</span> @sql_command <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SELECT @folder_id = pf2.[folderid]<br />
FROM ['</span> <span style="color: #808080;">+</span> @from_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackagefolders90] pf<br />
INNER JOIN ['</span> <span style="color: #808080;">+</span> @from_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackages90] p<br />
ON pf.folderid = p.folderid<br />
LEFT OUTER JOIN ['</span> <span style="color: #808080;">+</span> @to_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackagefolders90] pf2<br />
ON pf.[foldername] = pf2.[foldername]<br />
WHERE p.name = @package_name'</span><br />
<br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_command, N<span style="color: #FF0000;">'@package_name sysname, @folder_id uniqueidentifier OUTPUT'</span>, @package_name <span style="color: #808080;">=</span> @package_name, @folder_id<span style="color: #808080;">=</span>@folder_id <span style="color: #0000FF;">OUTPUT</span><br />
<br />
<span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">@@ROWCOUNT</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">1</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
<span style="color: #0000FF;">RAISERROR</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'This package exists in more than one location.'</span>, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">END</span><br />
<br />
<span style="color: #0000FF;">IF</span> @folder_id <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
<span style="color: #0000FF;">RAISERROR</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SSIS Folder does not exist.'</span>, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">END</span><br />
<br />
<span style="color: #0000FF;">SELECT</span> @sql_command <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DELETE ['</span> <span style="color: #808080;">+</span> @to_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackages90]<br />
WHERE name = @package_name'</span><br />
<br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_command, N<span style="color: #FF0000;">'@package_name sysname'</span>, @package_name <span style="color: #808080;">=</span> @package_name<br />
<br />
<span style="color: #0000FF;">SELECT</span> @sql_command <span style="color: #808080;">=</span> <span style="color: #FF0000;">'INSERT ['</span> <span style="color: #808080;">+</span> @to_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackages90]<br />
SELECT [name]<br />
,[id]<br />
,[description]<br />
,[createdate]<br />
,@folder_id AS [folderid]<br />
,[ownersid]<br />
,[packagedata]<br />
,[packageformat]<br />
,[packagetype]<br />
,[vermajor]<br />
,[verminor]<br />
,[verbuild]<br />
,[vercomments]<br />
,[verid]<br />
,[isencrypted]<br />
,[readrolesid]<br />
,[writerolesid]<br />
FROM ['</span> <span style="color: #808080;">+</span> @from_server_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].[msdb].[dbo].[sysdtspackages90]<br />
WHERE name = @package_name'</span><br />
<br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_command, N<span style="color: #FF0000;">'@package_name sysname, @folder_id uniqueidentifier'</span>, @package_name <span style="color: #808080;">=</span> @package_name, @folder_id<span style="color: #808080;">=</span>@folder_id</div></td></tr></tbody></table></div>
<p>Please let me know if you run into any issues, have any ideas that would make this stored procedure better or just want to share how you are using it. As always scripts from the internet are like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=ife5FfJ0rfM:0IQSt1O7ll4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=ife5FfJ0rfM:0IQSt1O7ll4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=ife5FfJ0rfM:0IQSt1O7ll4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=ife5FfJ0rfM:0IQSt1O7ll4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=ife5FfJ0rfM:0IQSt1O7ll4:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/ife5FfJ0rfM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/09/a-stored-procedure-to-move-ssis-packages-between-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/09/a-stored-procedure-to-move-ssis-packages-between-servers/</feedburner:origLink></item>
		<item>
		<title>Great News! SSMS Tools Pack 1.9 is Coming Out!</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/RrZXnb-jab0/</link>
		<comments>http://adventuresinsql.com/2010/08/great-news-ssms-tools-pack-1-9-is-coming-out/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 00:36:08 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[SQL 2008]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSMS Tools Pack]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=434</guid>
		<description><![CDATA[Mladen Prajdic recently announced that the newest version of SSMS Tools Pack is coming out and I am excited.
 <a href="http://adventuresinsql.com/2010/08/great-news-ssms-tools-pack-1-9-is-coming-out/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Mladen Prajdic (<a href="http://weblogs.sqlteam.com/mladenp/default.aspx">Blog</a>|<a href="http://twitter.com/MladenPrajdic">Twitter</a>) recently announced that the newest version of SSMS Tools Pack is coming out and I am excited.</p>
<p>Why am I excited?</p>
<p>Well, I am glad you asked.</p>
<p>I am excited because it will allow me to define my window colors in SQL Management Studio using regular expressions rather than having to define them each individually.</p>
<p>Why is that such a big deal?</p>
<p>I have 100s of servers and I am constantly adding new servers while decommissioning old ones. The sheer amount of changes that would have to be made manually has always kept me from being able to take advantage of window coloring. Rather than have 100s of rules I now have less than 10 regular expressions that cover all of my servers. Here, check it out:</p>
<div id="attachment_435" class="wp-caption aligncenter" style="width: 650px"><a href="http://adventuresinsql.com/wp-content/uploads/2010/08/ConnectionColoringOptions.jpg"><img class="size-full wp-image-435" title="ConnectionColoringOptions" src="http://adventuresinsql.com/wp-content/uploads/2010/08/ConnectionColoringOptions.jpg" alt="SSMS Tools Pack Connection Coloring Options Window" width="640" height="550" /></a><p class="wp-caption-text">Naming convention changed to protect the employed.</p></div>
<p>So is that all the SSMS Tools Pack does is color windows?</p>
<p>No, not at all. The SSMS Tools Pack is a large suite of plug-ins for SQL Management Studio available as a free download. There are several features that I cannot live without. My favorite feature is that it can be configured to keep a journal of all queries you have run. This can be especially useful if you work in an environment where a sys admin can push updates that cause your machine to reboot whenever they feel like it. If you are not familiar with all of the features currently in the product then please go check out the list <a href="http://www.ssmstoolspack.com/">here</a>.</p>
<p>If you have not tried out the SSMS Tools Pack then I highly suggest you give version 1.9 a whirl. I know I will.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=RrZXnb-jab0:OyVDeBkaeAo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=RrZXnb-jab0:OyVDeBkaeAo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=RrZXnb-jab0:OyVDeBkaeAo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=RrZXnb-jab0:OyVDeBkaeAo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=RrZXnb-jab0:OyVDeBkaeAo:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/RrZXnb-jab0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/08/great-news-ssms-tools-pack-1-9-is-coming-out/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/08/great-news-ssms-tools-pack-1-9-is-coming-out/</feedburner:origLink></item>
		<item>
		<title>How Can I Quickly Script Out Replication?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/JkuI3JPU4XU/</link>
		<comments>http://adventuresinsql.com/2010/07/how-can-i-quickly-script-out-replication/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 01:46:23 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[SSP]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=414</guid>
		<description><![CDATA[This script takes a distribution server name and an output directory as parameters then works through all publications on each of the servers that connects to the distribution server, scripting them out. <a href="http://adventuresinsql.com/2010/07/how-can-i-quickly-script-out-replication/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I recently finished taking down a bunch of servers that I was using to scale out my environment by forcing read only connections off of my main read-write servers. To make a long story short, hardware advances and the additional diagnostic information in SQL 2005 allowed me to consolidate to a few very powerful, reasonably well-tuned read-write servers. The consolidation of servers allowed me to save a ton of power and cooling along with some rack space and a good size chunk of SAN disk. </p>
<p>Taking down the servers means that I now have to update all of my environment diagrams, server configuration scripts and even a spreadsheet or two. Anyone who has ever done this before is cringing right now. One of the worst tasks is updating the replication scripts. I script my replication settings to a network share just in case I do something silly and need to revert to my last know good setup. The scripts can really save my bacon but they are incredibly tedious to create. I have to go into Management Studio, right-click on each publication, select generate script, select script to file then finally find the existing file for that database to add to or decide there is not one and start a new file. With the amount of scripts I had to create it would have easily taken 4, make that 8 hours with interruptions to get everything scripted.</p>
<p>Given, that the whole process would have taken hours and probably would have gotten screwed up along the way I decided to turn to PowerShell. Unfortunately, I did not have a script ready to go&#8230;.WHHAAAT?&#8230;yeah I know..I don&#8217;t have a script for everything..so I threw the question out to Twitter. Aaron Nelson (<a href="http://sqlvariant.com/wordpress/">Blog</a>|<a href="http://www.twitter.com/SQLvariant">Twitter</a>) came back right away, pointing me toward <a href="http://sqlpsx.codeplex.com/">SQL PowerShell Extensions</a> (SQLPSX) and very quickly I had a working script. If you are not familiar with SQLPSX please take some time to check it out. It really makes coding PowerShell for SQL Server fast. <strong>More importantly, if you are not part of the SQL community on Twitter then get there first.</strong></p>
<p>The actual script is not terribly complex. It takes a distribution server name and an output directory as parameters then works through all publications on each of the servers that connects to the distribution server, scripting them out. </p>
<p>I have only run this script against a dedicated distribution server but it should also work where the publisher is the distributor too. </p>
<p>I spent about 4 hours throwing the script together and generated all of the scripts I needed in a little over 1 minute.</p>
<p>With that, here is the script:</p>
<p><em>Update: Chad Miller (<a href="http://sev17.com/">Blog</a>|<a href="http://twitter.com/cmille19">Twitter</a>) showed how this script could take better advantage of the features of SQLPSX. His version of the script is available here: <a href="http://sev17.com/2010/08/quickly-script-out-replication-redux/">http://sev17.com/2010/08/quickly-script-out-replication-redux/</a></em></p>
<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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;">$sqlServer</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$outputDirectory</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">bool</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$scriptPerPublication</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$sqlServer</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$sqlserver</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-Prompt</span> <span style="color: #800000;">&quot;Please provide a value for -sqlServer&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$outputDirectory</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$outputDirectory</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-Prompt</span> <span style="color: #800000;">&quot;Please provide a value for -outputDirectory&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0000FF;">function</span> ScriptPublications<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <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;">$sqlServer</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$outputDirectory</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">bool</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$scriptPerPublication</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Import<span style="color: pink;">-</span>Module Repl<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$path</span> <span style="color: pink;">=</span> &nbsp;<span style="color: #800000;">&quot;$outputDirectory$((get-date).toString('yyyy-MMM-dd_HHmmss'))&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #800080;">$path</span> <span style="color: #008080; font-style: italic;">-ItemType</span> Directory <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$publication</span> <span style="color: #0000FF;">in</span> Get<span style="color: pink;">-</span>ReplPublication <span style="color: #800080;">$sqlServer</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$fileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0}{1}.sql&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$path</span><span style="color: pink;">,</span><span style="color: #800080;">$publication</span>.DatabaseName.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$scriptPerPublication</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0}{1}_{2}.sql&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$path</span><span style="color: pink;">,</span><span style="color: #800080;">$publication</span>.DatabaseName.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$publication</span>.Name.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$progressText</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Scripting {0} to {1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$publication</span>.Name.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$fileName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800080;">$progressText</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$publication</span>.Script<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::Creation `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeArticles `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludePublisherSideSubscriptions `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeCreateSnapshotAgent `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeGo `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::EnableReplicationDB `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludePublicationAccesses `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeCreateLogreaderAgent `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeCreateQueuereaderAgent `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">-bor</span> &nbsp;<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.scriptoptions<span style="color: #000000;">&#93;</span>::IncludeSubscriberSideSubscriptions<span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$fileName</span> <span style="color: #008080; font-style: italic;">-Append</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Management.Common.ServerConnection<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$serverConnection</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.SqlServer.Management.Common.ServerConnection<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sqlServer</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#91;</span>Microsoft.SqlServer.Replication.ReplicationServer<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$distributor</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.SqlServer.Replication.ReplicationServer<span style="color: #000000;">&#40;</span><span style="color: #800080;">$serverConnection</span><span style="color: #000000;">&#41;</span>;<br />
<br />
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$distributionPublisher</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$distributor</span>.DistributionPublishers<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$distributionPublisher</span>.PublisherType <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;MSSQLSERVER&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$path</span> <span style="color: pink;">=</span> <span style="color: #800080;">$outputDirectory</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;from_&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$distributionPublisher</span>.Name.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;_&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ScriptPublications <span style="color: pink;">-</span>sqlServer <span style="color: #800080;">$distributionPublisher</span>.Name <span style="color: pink;">-</span>outputDirectory <span style="color: #800080;">$path</span> <span style="color: pink;">-</span>scriptPerPublication <span style="color: #800080;">$false</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>As usual, I hope you find this script helpful. Please let me know if you run into any issues with it or know a better way to do the same thing. Please keep in mind that scripts from the internet are like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=JkuI3JPU4XU:BQjNHc2eqcc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=JkuI3JPU4XU:BQjNHc2eqcc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=JkuI3JPU4XU:BQjNHc2eqcc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=JkuI3JPU4XU:BQjNHc2eqcc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=JkuI3JPU4XU:BQjNHc2eqcc:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/JkuI3JPU4XU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/07/how-can-i-quickly-script-out-replication/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/07/how-can-i-quickly-script-out-replication/</feedburner:origLink></item>
		<item>
		<title>What is an Easy Way to Return Results from a CLR Stored Procedure?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/7Fummw9wKRU/</link>
		<comments>http://adventuresinsql.com/2010/07/what-is-an-easy-way-to-return-results-from-a-clr-stored-procedure/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:19:18 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[CLR]]></category>
		<category><![CDATA[SSC]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=393</guid>
		<description><![CDATA[This post describes a helper class that I came up with to handle returning values from a CLR stored procedure. <a href="http://adventuresinsql.com/2010/07/what-is-an-easy-way-to-return-results-from-a-clr-stored-procedure/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>What is an Easy Way to Return Results from a CLR Stored Procedure? The question sounds simple enough but yet when I went searching for answers I could not find it. This post describes a helper class that I came up with to handle returning values from a CLR stored procedure.</p>
<h2>My Solution</h2>
<p>When I set out to write my first CLR stored procedure I expected to be able to do something easy, like write a method that returns an array and have SQL Server work out how to display it as a recordset. In the end I found that CLR works sort of like that, except that you have to figure out all the sizes, declare the structure then handle the passing back of each and every cell in each and every row. I guess that is OK, but if you have read any of my other posts you will have noticed a common theme: I am Lazy. Being as lazy as I am, I started digging into Intellisense to see what methods the various classes exposed to make my life easier. Pretty quickly I found SqlMetaData.InferFromValue to define the columns of the result without having to figure out what SQLMetaData type each column in the result set converted to.</p>
<p>Armed with a way to quickly define a column in a recordset I started adding iterative code to walk through various types of objects. I started with walking a DataReader then added DataTables and DataSets, then finally progressed to using reflection to display all of the properties of an object or even all of the properties for all of the objects in an array. I have also added an optional debug flag to output information about the result set to make it easy to define a temporary table to hold the results. Now I have a helper class that I can reference from my CLR stored procedures to quickly return results without very much time spent coding. </p>
<p>Here is an example to show how easy the helper class makes it to code a CLR stored procedure:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">AdventuresInSql</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> StoredProcedures<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlServer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Server</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SqlProcedure</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> FileInfo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> filePath<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; FileInfo fileInfo <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileInfo<span style="color: #008000;">&#40;</span>filePath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlClrHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderResults</span><span style="color: #008000;">&#40;</span>fileInfo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></div></td></tr></tbody></table></div>
<p>On my systems, I deploy the helper class in it&#8217;s own assembly, add the assembly to the server I want to develop against, then open a new project, connect to that server, reference that assembly and write my code. I realize that most people are not using CLR in any distributed manner, making it easiest to just include the class in their project and run with it there.</p>
<p><strong><em>Warnings: I highly suggest taking the time to deploy this class in it&#8217;s own assembly. The assembly this class resides in has to be marked UNSAFE. The database this assembly is deployed to must also be marked TRUSTWORTHY so I highly suggest keeping CLR objects in their own highly secured database. Most importantly, if you do not know what these setttings do stop now and find out before moving any further. UPDATE: Per Adam Machanic&#8217;s (<a href="http://sqlblog.com/blogs/adam_machanic">Blog</a>|<a href="http://www.twitter.com/AdamMachanic">Twitter</a>) comments below, the TRUSTWORTHY setting is not needed if you use certificates.</em></strong></p>
<p>With that, here is the code for the helper class <em>Updated 7/26/2010 to better handle null values, increase performance and make easier to use. The biggest changes are switching to generic methods rather than using object typed parameters and getting column definitions more efficiently.</em>:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.OleDb</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlClient</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Globalization</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Reflection</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Server</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">sealed</span> <span style="color: #6666cc; font-weight: bold;">class</span> SqlClrHelper<br />
<span style="color: #008000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Member Variables</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> ARGUMENT_EXCEPTION_STRING <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Extract of property: &quot;</span><span style="color: #008000;">&#123;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#125;</span><span style="color: #666666;">&quot; failed with the following message: {1}&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> COLUMN_NAME <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ColumnName&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> COLUMN_SIZE <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ColumnSize&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> DATA_TYPE <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;DataType&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> DEBUG_WARNING_MESSAGE <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;***Turn off debug before trying to select into a table to avoid conversion exceptions***&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> OBJECT_TYPE_DIFFERENT_EXCEPTION <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;All objects in objectsToRender[] must be of the same type.&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">String</span> TO_STRING <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ToString()&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Internal Methods</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;Class will only ever contain static methods.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///Added private constructor to prevent compiler from generating default constructor.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> SqlClrHelper<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a column name, type and maximum length, returning the column definition as SqlMetaData.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.String&quot;&gt;A column name to be used in the returned Microsoft.SqlServer.Server.SqlMetaData.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Type&quot;&gt;A column data type to be used in the returned Microsoft.SqlServer.Server.SqlMetaData.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Int32&quot;&gt;The maximum length of the column to be used in the returned Microsoft.SqlServer.Server.SqlMetaData.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> SqlMetaData ParseSqlMetaData<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> columnName, Type type, Int64 maxLength<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlParameter sqlParameter <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlParameter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">DbType</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>DbType<span style="color: #008000;">&#41;</span>TypeDescriptor<span style="color: #008000;">.</span><span style="color: #0000FF;">GetConverter</span><span style="color: #008000;">&#40;</span>sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">DbType</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertFrom</span><span style="color: #008000;">&#40;</span>type<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #6666cc; font-weight: bold;">Char</span> <span style="color: #008000;">||</span> sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #0000FF;">NChar</span> <span style="color: #008000;">||</span> sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #0000FF;">NVarChar</span> <span style="color: #008000;">||</span> sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #0000FF;">VarChar</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>maxLength <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">8000</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxLength <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlMetaData<span style="color: #008000;">&#40;</span>columnName, sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span>, maxLength<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">||</span> sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span> <span style="color: #008000;">==</span> SqlDbType<span style="color: #008000;">.</span><span style="color: #0000FF;">NText</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlMetaData<span style="color: #008000;">&#40;</span>columnName, sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlMetaData<span style="color: #008000;">&#40;</span>columnName, sqlParameter<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlDbType</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a single object and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;&lt;T&gt;&quot;&gt;A populated object.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CodeAnalysis</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SuppressMessage</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Microsoft.Performance&quot;</span>, <span style="color: #666666;">&quot;CA1811:AvoidUncalledPrivateCode&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T objectToRender<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>objectToRender, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes the SqlMetaData created to render an object and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Collections.Generic.List&lt;Microsoft.SqlServer.Server&gt;&quot;&gt;A reference to a populated SqlMetaData List.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> WriteRecordStructure<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span> sqlMetaDataList<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Public Methods</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region RenderResults Overloads</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#region Pass-Through Overloads</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a DataSet and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.DataSet&quot;&gt;A reference to a populated DataSet.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>DataSet dataSet<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>dataSet<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a DataSet and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.DataSet&quot;&gt;A reference to a populated DataSet.&lt;/param&gt; </span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Boolean&quot;&gt;A boolean value indicating whether or not to return information</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// about the record structure to the client.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>DataSet dataSet, Boolean isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>DataTable dataTable <span style="color: #0600FF; font-weight: bold;">in</span> dataSet<span style="color: #008000;">.</span><span style="color: #0000FF;">Tables</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>dataTable, isDebugOn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a DataTable and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.DataTable&quot;&gt;A reference to a populated DataTable.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>DataTable dataTable<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>dataTable, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes an OleDbDataReader and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.OleDb.OleDbDataReader&quot;&gt;A reference to a populated OleDbDataReader.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>OleDbDataReader dataReader<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>dataReader, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a single object and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;&lt;T&gt;&quot;&gt;A reference to a populated object.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Boolean&quot;&gt;A boolean value indicating whether or not to return information</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// about failed argument exceptions and record structure to the client.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T objectToRender, Boolean isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> objectsToRender <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> T<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; objectsToRender<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> objectToRender<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>objectsToRender, isDebugOn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes an array of objects and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Object[]&quot;&gt;A reference to a populated object.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> objectsToRender<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>objectsToRender, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes a DataTable and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.DataTable&quot;&gt;A reference to a populated DataTable.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Boolean&quot;&gt;A boolean value indicating whether or not to return information</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// about the record structure to the client.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>DataTable dataTable, Boolean isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span> sqlMetaDataList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> dataTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Rows</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemArray</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ParseSqlMetaData<span style="color: #008000;">&#40;</span>dataTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Columns</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ColumnName</span>, dataTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Columns</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataType</span>, dataTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Columns</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLength</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlDataRecord sqlDataRecord <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlDataRecord<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsStart</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsSendingResults</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>DataRow dataRow <span style="color: #0600FF; font-weight: bold;">in</span> dataTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Rows</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlDataRecord<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValues</span><span style="color: #008000;">&#40;</span>dataRow<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemArray</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsRow</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteRecordStructure<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes an OleDbDataReader and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Data.OleDb.OleDbDataReader&quot;&gt;A reference to a populated OleDbDataReader.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Boolean&quot;&gt;A boolean value indicating whether or not to return information</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// about the record structure to the client.&lt;/param&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&#40;</span>OleDbDataReader oleDBDataReader, Boolean isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Int64 columnSize <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span> sqlMetaDataList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>DataRow dataRow <span style="color: #0600FF; font-weight: bold;">in</span> oleDBDataReader<span style="color: #008000;">.</span><span style="color: #0000FF;">GetSchemaTable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Rows</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Int64<span style="color: #008000;">.</span><span style="color: #0000FF;">TryParse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Int32<span style="color: #008000;">&#41;</span>dataRow<span style="color: #008000;">&#91;</span>COLUMN_SIZE<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>CultureInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentCulture</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> columnSize<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ParseSqlMetaData<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#41;</span>dataRow<span style="color: #008000;">&#91;</span>COLUMN_NAME<span style="color: #008000;">&#93;</span>, <span style="color: #008000;">&#40;</span>Type<span style="color: #008000;">&#41;</span>dataRow<span style="color: #008000;">&#91;</span>DATA_TYPE<span style="color: #008000;">&#93;</span>, columnSize<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ParseSqlMetaData<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#41;</span>dataRow<span style="color: #008000;">&#91;</span>COLUMN_NAME<span style="color: #008000;">&#93;</span>, <span style="color: #008000;">&#40;</span>Type<span style="color: #008000;">&#41;</span>dataRow<span style="color: #008000;">&#91;</span>DATA_TYPE<span style="color: #008000;">&#93;</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlDataRecord sqlDataRecord <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlDataRecord<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> objects <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&#91;</span>sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsStart</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsSendingResults</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>oleDBDataReader<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oleDBDataReader<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValues</span><span style="color: #008000;">&#40;</span>objects<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlDataRecord<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValues</span><span style="color: #008000;">&#40;</span>objects<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsRow</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteRecordStructure<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>oleDBDataReader<span style="color: #008000;">.</span><span style="color: #0000FF;">NextResult</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenderResults<span style="color: #008000;">&#40;</span>oleDBDataReader, isDebugOn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">///&lt;para&gt;This method takes an array of objects and renders it back to the client.&lt;/para&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;&lt;T&gt;[]&quot;&gt;A reference to an array of populated objects.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;System.Boolean&quot;&gt;A boolean value indicating whether or not to return information</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// about failed argument exceptions and record structure to the client.&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderResults<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> objectsToRender, Boolean isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span> sqlMetaDataList <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>SqlMetaData<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;&gt;</span> sqlMetaDataValues <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlDataRecord sqlDataRecord <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Type objectType <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> objectsToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>objectsToRender<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T objectToRender <span style="color: #008000;">=</span> objectsToRender<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>objectType <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objectType <span style="color: #008000;">=</span> objectToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>objectToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> objectType<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> InvalidCastException<span style="color: #008000;">&#40;</span>OBJECT_TYPE_DIFFERENT_EXCEPTION<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>PropertyInfo property <span style="color: #0600FF; font-weight: bold;">in</span> objectToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlMetaData sqlMetaData <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>property<span style="color: #008000;">.</span><span style="color: #0000FF;">CanRead</span> <span style="color: #008000;">&amp;&amp;</span> property<span style="color: #008000;">.</span><span style="color: #0000FF;">GetIndexParameters</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaData <span style="color: #008000;">=</span> SqlMetaData<span style="color: #008000;">.</span><span style="color: #0000FF;">InferFromValue</span><span style="color: #008000;">&#40;</span>property<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>objectToRender, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>, property<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> sqlMetaData<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLength</span> <span style="color: #008000;">&lt;</span> sqlMetaData<span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLength</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> sqlMetaData<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaData <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlMetaData <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>sqlMetaData<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sqlMetaDataValues<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> i<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataValues<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">Object</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataValues<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>property<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>objectToRender, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>ArgumentException ex<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>CultureInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentCulture</span>, ARGUMENT_EXCEPTION_STRING, property<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, ex<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>i <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>SqlMetaData<span style="color: #008000;">.</span><span style="color: #0000FF;">InferFromValue</span><span style="color: #008000;">&#40;</span>objectToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, TO_STRING<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataValues<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>objectToRender<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sqlDataRecord <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SqlDataRecord<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsStart</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsSendingResults</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlMetaDataValues<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ForEach</span><span style="color: #008000;">&#40;</span>sqlMetaDataValue <span style="color: #008000;">=&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlDataRecord<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValues</span><span style="color: #008000;">&#40;</span>sqlMetaDataValue<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsRow</span><span style="color: #008000;">&#40;</span>sqlDataRecord<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Pipe</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SendResultsEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>isDebugOn<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteRecordStructure<span style="color: #008000;">&#40;</span>sqlMetaDataList<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Conclusion</h2>
<p>I fear that by making it easy to use CLR that I may be opening up a can of worms. I ask that before using CLR that you make sure that it is the best way to accomplish the task you have been given. </p>
<p>As usual, I hope you find this class useful. Please let me know if you run into any issues with it or know a better way to do the same thing. Please keep in mind that code from the internet is like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=7Fummw9wKRU:JC0Wt1ArNuE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=7Fummw9wKRU:JC0Wt1ArNuE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=7Fummw9wKRU:JC0Wt1ArNuE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=7Fummw9wKRU:JC0Wt1ArNuE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=7Fummw9wKRU:JC0Wt1ArNuE:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/7Fummw9wKRU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/07/what-is-an-easy-way-to-return-results-from-a-clr-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/07/what-is-an-easy-way-to-return-results-from-a-clr-stored-procedure/</feedburner:origLink></item>
		<item>
		<title>Why Would a Delete Make My Database Grow?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/IHEK7aAAoQ4/</link>
		<comments>http://adventuresinsql.com/2010/06/why-would-a-delete-make-my-database-grow/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 17:20:18 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[File Management]]></category>
		<category><![CDATA[RCSI]]></category>
		<category><![CDATA[Read Committed Snapshot Isolation]]></category>
		<category><![CDATA[SSC]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=361</guid>
		<description><![CDATA[A while back I had a developer come to me complaining that every time they ran a large delete statement on a certain database the delete would fail with a message claiming the database was full. My first instinct was that they were doing something wrong so I asked for the script so I could try it myself. To my surprise, running the delete actually did fill the database. <a href="http://adventuresinsql.com/2010/06/why-would-a-delete-make-my-database-grow/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>A while back I had a developer come to me complaining that every time they ran a large delete statement on a certain database the delete would fail with a message claiming the database was full. My first instinct was that they were doing something wrong so I asked for the script so I could try it myself. To my surprise, running the delete actually did fill the database.</p>
<h2>Troubleshooting</h2>
<p>To figure out why a delete would cause a database to grow, I started with Profiler to see if anything was running as a side-effect of the deletes. The only thing that Profiler showed was the delete. Unable to explain what was happening, I threw the question to <a href="http://twitter.com/#search?q=%23sqlhelp">#SqlHelp</a> on Twitter. Almost immediately, Paul Randal (<a href="http://www.sqlskills.com/blogs/paul/">Blog</a>|<a href="http://twitter.com/PaulRandal">Twitter</a>) asked if I had Read Committed Snapshot Isolation (RCSI) turned on for that database. I confirmed that the database did in fact have RCSI turned on and Paul explained that what I was seeing was SQL Server adding the pointers to the version store to the data pages as they are marked deleted.</p>
<h2>Moving Forward</h2>
<p>Once I knew what the issue was my mind began to shift gears into how to prevent it from biting me in production. The obvious answer is to set the database size to be sufficiently high enough to allow extra space for large updates or deletes to add version information to the data pages. The problem with this approach is that eventually the reason for the free space will be forgotten and normal growth of the database will eventually eat up that free space.</p>
<p>While looking for options I remembered how I had a similar experience rebuilding indexes to move them to a new file group on new disk. The idea of the project was to move the database to new disk with minimal downtime. To accomplish the move I created a new file group and rebuilt all of the indexes onto it, starting with clustered indexes. Once the primary data file was down to just the system tables I shrunk it, took the whole database offline, moved the file and brought the database back online. The total downtime was about 15 seconds but all of the work took about a week. The work I was doing had to be minimally disruptive so I used the ONLINE flag along with DROP_EXISTING to recreate the indexes.  I was surprised to find out at the end of that work to find out that my database had grown significantly in size. After a ton of research I discovered that the ONLINE flag was adding version information to each page, leading to the unexpected growth.</p>
<p>Could the version information for online index operations be the same as what is used by Read Committed Snapshot Isolation?</p>
<p>Could rebuilding all of the indexes in my database with help me to pre-size my database, avoiding later surprises in production?</p>
<p>How would I go about proving my theory?</p>
<h2>The Proof</h2>
<p>To prove my theory that rebuilding my indexes with would allow me to pre-size my database; I found a quiet corner of the development environment and created a test database.</p>
<p>Here is the script to create the database if you should choose to follow along at home:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> master<br />
GO<br />
<span style="color: #0000FF;">IF</span> <span style="color: #808080;">EXISTS</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">databases</span> <span style="color: #0000FF;">WHERE</span> name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'RecordSizeTest'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">DATABASE</span> RecordSizeTest<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">DATABASE</span> RecordSizeTest<br />
GO<br />
<br />
<span style="color: #0000FF;">USE</span> RecordSizeTest<br />
GO<br />
<span style="color: #0000FF;">IF</span> <span style="color: #808080;">EXISTS</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">tables</span> <span style="color: #0000FF;">WHERE</span> name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TestTable'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">TestTable</span><br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">TestTable</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<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;">NOT</span> <span style="color: #808080;">NULL</span>,<br />
&nbsp; &nbsp; varchar_value &nbsp; <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">400</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,<br />
&nbsp; &nbsp; bit_value &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">bit</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,<br />
&nbsp; &nbsp; create_date &nbsp; &nbsp; <span style="color: #0000FF;">smalldatetime</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">DEFAULT</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">UNIQUE</span> <span style="color: #0000FF;">CLUSTERED</span> <span style="color: #0000FF;">INDEX</span> IX_TestTable_id <span style="color: #0000FF;">ON</span> dbo.<span style="color: #202020;">TestTable</span> <span style="color: #808080;">&#40;</span>id<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> &nbsp;dbo.<span style="color: #202020;">TestTable</span> <span style="color: #808080;">&#40;</span>varchar_value, bit_value<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> &nbsp;<span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'TEST'</span>, <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">2</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; &nbsp;dbo.<span style="color: #202020;">TestTable</span><br />
GO <span style="color: #000;">100</span><br />
<br />
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> RecordSizeTest <span style="color: #0000FF;">SET</span> READ_COMMITTED_SNAPSHOT <span style="color: #0000FF;">ON</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">TestTable</span></div></td></tr></tbody></table></div>
<p>Now that the database is created, the first step is to see what the database pages look like by default using DBCC IND and DBCC PAGE.</p>
<p><em>Note: The commands I am using are well-covered elsewhere so I am not going to spend any time describing them beyond just showing how I used them. It goes without saying that you should not run anything on your systems without first taking the time to understand what it does.</em></p>
<p>The first step is to figure out where the table ended up. Time for DBCC IND:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> <span style="color: #808080;">IN</span>D<span style="color: #808080;">&#40;</span>RecordSizeTest, TestTable, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Below are the results of the DBCC IND command. To keep things easy I am looking for the first page of the table. To find it I look for a page that has a PrevPageId of 0 and a PageType of 1. In this case the page I am looking for is 145.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PageFID PagePID &nbsp; &nbsp; IAMFID IAMPID &nbsp; &nbsp; &nbsp;ObjectID &nbsp; &nbsp;IndexID &nbsp; &nbsp; PartitionNumber PartitionID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iam_chain_type &nbsp; &nbsp; &nbsp; PageType IndexLevel NextPageFID NextPagePID PrevPageFID PrevPagePID<br />
------- ----------- ------ ----------- ----------- ----------- --------------- -------------------- -------------------- -------- ---------- ----------- ----------- ----------- -----------<br />
1 &nbsp; &nbsp; &nbsp; 146 &nbsp; &nbsp; &nbsp; &nbsp; NULL &nbsp; NULL &nbsp; &nbsp; &nbsp; &nbsp;2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038845440 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; NULL &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
1 &nbsp; &nbsp; &nbsp; 145 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;146 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038845440 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 150 &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
1 &nbsp; &nbsp; &nbsp; 150 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;146 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038845440 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 153 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 145<br />
1 &nbsp; &nbsp; &nbsp; 153 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;146 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038845440 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 150<br />
<br />
(4 row(s) affected)<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Next I want to get a look at that page so I run the following command:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON<span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">145</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Below are the DBCC PAGE results. The 2 things to really notice are that free space on the page, m_freeCnt is currently 212 bytes and that the values for Record Attributes are NULL_BITMAP and VARIABLE_COLUMNS. While we are looking at this page I am also making sure that the record in slot 0 has an id of 1 for the next step in the test.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:145)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6300<br />
<br />
bpage = 0x000000009018C000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:145)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 31047<br />
bstat = 0x6c00009 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x21432159 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x000000009018C000<br />
<br />
m_pageId = (1:145) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x200<br />
m_objId (AllocUnitId.idObj) = 28 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039762944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038845440 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:150)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 212<br />
m_freeData = 7864 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:159:16)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 0<br />
m_tornBits = -436072588 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = NOT ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x60 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x60 Length 16<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP &nbsp; &nbsp; Record Size = 16<br />
<br />
Memory Dump @0x000000002309A060<br />
<br />
0000000000000000: &nbsp; 10000d00 01000000 00530384 9d040000 †.........S..... <br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x70 Length 24<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309A070<br />
<br />
0000000000000000: &nbsp; 30000d00 02000000 01530384 9d040000 †0........S..... <br />
0000000000000010: &nbsp; 01001800 54455354 †††††††††††††††††††....TEST &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 2 Offset 0x88 Length 28<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 28 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309A088<br />
<br />
0000000000000000: &nbsp; 30000d00 03000000 00530384 9d040000 †0........S..... <br />
0000000000000010: &nbsp; 01001c00 54455354 54455354 ††††††††††....TESTTEST &nbsp; &nbsp; <br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip<br />
Slot 57 Offset 0x1dc0 Length 248<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 248 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Memory Dump @0x000000002309BDC0<br />
<br />
0000000000000000: &nbsp; 30000d00 3a000000 01530384 9d040000 †0...:....S..... <br />
0000000000000010: &nbsp; 0100f800 54455354 54455354 54455354 †..ø.TESTTESTTEST <br />
0000000000000020: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000030: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000040: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000050: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000060: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000070: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000080: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000090: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000A0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000B0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000C0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000D0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000E0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000F0: &nbsp; 54455354 54455354 †††††††††††††††††††TESTTEST &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 2 Offset 0x14 Length 228 Length (physical) 228<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE<br />
STTESTTESTTESTTEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (3a0026382d41) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Next I want to delete the first row from the table to see what effect that has. I picked the first row because I already know what page it is on so I can quickly see the impact, if any, of deleting it. I chose to do this in a transaction to also see what effect a rollback might have. Here is the next bit of code in the test:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON<span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">BEGIN</span> <span style="color: #0000FF;">TRANSACTION</span><br />
<br />
<span style="color: #0000FF;">DELETE</span> &nbsp;dbo.<span style="color: #202020;">TestTable</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; id <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">145</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">ROLLBACK</span><br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">145</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Below are the latest DBCC PAGE results from before the rollback. Right away it is clear that the row in Slot 0 has been deleted because it&#8217;s Record Type is now GHOST_DATA_RECORD. It is also noteable that even though the row has been marked deleted the m_freeCnt on the page has gone down to 198. Sticking with our theory, the reduction in free space should be caused by the addition of version information and, sure enough, the Record Attributes now include VERSIONING_INFO and a new Version Information section is visible with a Transaction Timestamp and a Version Pointer to a location in TempDB. We have now proven that we know how to make a page grow on demand by running a delete.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:145)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6300<br />
<br />
bpage = 0x000000009018C000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:145)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 31887<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x21432159 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x000000009018C000<br />
<br />
m_pageId = (1:145) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x2000<br />
m_objId (AllocUnitId.idObj) = 28 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039762944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038845440 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:150)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 198<br />
m_freeData = 7956 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:324:10)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:973) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 1<br />
m_tornBits = -436072588 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = NOT ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x68 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x1ef6 Length 30<br />
<br />
Record Type = GHOST_DATA_RECORD &nbsp; &nbsp; &nbsp;Record Attributes = &nbsp;NULL_BITMAP VERSIONING_INFO<br />
Record Size = 30 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309BEF6<br />
<br />
0000000000000000: &nbsp; 5c000d00 01000000 00530384 9d040000 †........S..... <br />
0000000000000010: &nbsp; b0010000 01000000 3dbd0500 0000††††††°.......=½.... &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376125<br />
&nbsp; &nbsp; Version Pointer: (file 1 page 432 currentSlotId 0)<br />
<br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x1ede Length 24<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309BEDE<br />
<br />
0000000000000000: &nbsp; 30000d00 02000000 01530384 9d040000 †0........S..... <br />
0000000000000010: &nbsp; 01001800 54455354 †††††††††††††††††††....TEST &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 2 Offset 0x88 Length 28<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 28 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309A088<br />
<br />
0000000000000000: &nbsp; 30000d00 03000000 00530384 9d040000 †0........S..... <br />
0000000000000010: &nbsp; 01001c00 54455354 54455354 ††††††††††....TESTTEST &nbsp; &nbsp; <br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
Slot 57 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 2 Offset 0x14 Length 228 Length (physical) 228<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE<br />
STTESTTESTTESTTEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (3a0026382d41) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Next are the DBCC PAGE results from after the rollback. The m_freeCnt has gone back to 212, the row in slot 0 no longer shows as deleted and the versioning information has been removed. The fact that the versioning information goes away as part of the rollback is interesting. It means that no matter how many times I try to do a delete that fills the database I will always start from the same point. It makes perfect sense in terms of ACID but until I saw it for myself I was not sure how it would work.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:145)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6300<br />
<br />
bpage = 0x000000009018C000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:145)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 32941<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x21432159 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x000000009018C000<br />
<br />
m_pageId = (1:145) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x6000<br />
m_objId (AllocUnitId.idObj) = 28 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039762944 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038845440 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:150)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 212<br />
m_freeData = 7972 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:324:13)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:973) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 0<br />
m_tornBits = -436072588 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = NOT ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x60 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x1f14 Length 16<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP &nbsp; &nbsp; Record Size = 16<br />
<br />
Memory Dump @0x000000002309BF14<br />
<br />
0000000000000000: &nbsp; 10000d00 01000000 00530384 9d040000 †.........S..... <br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x1ede Length 24<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x000000002309BEDE<br />
<br />
0000000000000000: &nbsp; 30000d00 02000000 01530384 9d040000 †0........S..... <br />
0000000000000010: &nbsp; 01001800 54455354 †††††††††††††††††††....TEST &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) <br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
Slot 57 Offset 0x1dc0 Length 248<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS<br />
Record Size = 248 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Memory Dump @0x000000002309BDC0<br />
<br />
0000000000000000: &nbsp; 30000d00 3a000000 01530384 9d040000 †0...:....S..... <br />
0000000000000010: &nbsp; 0100f800 54455354 54455354 54455354 †..ø.TESTTESTTEST <br />
0000000000000020: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000030: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000040: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000050: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000060: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000070: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000080: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000090: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000A0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000B0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000C0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000D0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000E0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000F0: &nbsp; 54455354 54455354 †††††††††††††††††††TESTTEST &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 58 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 2 Offset 0x14 Length 228 Length (physical) 228<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE<br />
STTESTTESTTESTTEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 57 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 57 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (3a0026382d41) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Now that I have proven that I can delete a record in a database that uses Read Committed Snapshot Isolation and cause space usage to increase I now want to repeat the test after rebuilding the clustered index on the table with ONLINE=ON. Here is the next bit of code to run:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">UNIQUE</span> <span style="color: #0000FF;">CLUSTERED</span> <span style="color: #0000FF;">INDEX</span> IX_TestTable_id <span style="color: #0000FF;">ON</span> dbo.<span style="color: #202020;">TestTable</span> <span style="color: #808080;">&#40;</span>id<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">WITH</span> <span style="color: #808080;">&#40;</span>ONL<span style="color: #808080;">IN</span>E<span style="color: #808080;">=</span><span style="color: #0000FF;">ON</span>, DROP_EXIST<span style="color: #808080;">IN</span>G<span style="color: #808080;">=</span><span style="color: #0000FF;">ON</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Now that the index has been rebuilt it is time to figure out where it ended up. Time for DBCC IND:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> <span style="color: #808080;">IN</span>D<span style="color: #808080;">&#40;</span>RecordSizeTest, TestTable, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Based on the results of DBCC IND we are looking for Page 156. It is noteable that DBCC IND returned 5 rows this time instead of 4. More pages generally means more data so lets dig into it.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PageFID PagePID &nbsp; &nbsp; IAMFID IAMPID &nbsp; &nbsp; &nbsp;ObjectID &nbsp; &nbsp;IndexID &nbsp; &nbsp; PartitionNumber PartitionID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iam_chain_type &nbsp; &nbsp; &nbsp; PageType IndexLevel NextPageFID NextPagePID PrevPageFID PrevPagePID<br />
------- ----------- ------ ----------- ----------- ----------- --------------- -------------------- -------------------- -------- ---------- ----------- ----------- ----------- -----------<br />
1 &nbsp; &nbsp; &nbsp; 157 &nbsp; &nbsp; &nbsp; &nbsp; NULL &nbsp; NULL &nbsp; &nbsp; &nbsp; &nbsp;2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038910976 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; NULL &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
1 &nbsp; &nbsp; &nbsp; 156 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;157 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038910976 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 160 &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br />
1 &nbsp; &nbsp; &nbsp; 160 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;157 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038910976 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 161 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 156<br />
1 &nbsp; &nbsp; &nbsp; 161 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;157 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038910976 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 162 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 160<br />
1 &nbsp; &nbsp; &nbsp; 162 &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp;157 &nbsp; &nbsp; &nbsp; &nbsp; 2105058535 &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72057594038910976 &nbsp; &nbsp;In-row data &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 161<br />
<br />
(5 row(s) affected)<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Here is the syntax of the next DBCC PAGE command to run:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON<span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">156</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>The results below seem quite different. First off, m_freeCnt is 680 instead of 212. Adding version information should not increase free space so there must be less records here, m_slotCnt proves that. This page has 53 slots or rows while the earlier page held 58 rows of data. That proves that the extra row in DBCC IND is an extra row of data that was added after the rebuild of the index to add the versioning information. Looking at the record in slot 0, it now looks like it did before the rollback of the delete. The Record Attributes include VERSIONING_INFO and there is a Version Information section just below that. The Version Information includes a Transaction Timestamp from when the index was rebuilt but no Version Pointer because the row is unchanged.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:156)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6080<br />
<br />
bpage = 0x0000000090182000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:156)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 34110<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x432159bb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x0000000090182000<br />
<br />
m_pageId = (1:156) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x2000<br />
m_objId (AllocUnitId.idObj) = 29 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039828480 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038910976 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:160)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 680<br />
m_freeData = 7406 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:385:19)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 0<br />
m_tornBits = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x60 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x60 Length 30<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VERSIONING_INFO<br />
Record Size = 30 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4A060<br />
<br />
0000000000000000: &nbsp; 50000d00 01000000 d0530384 9d040000 †P.......ÐS..... <br />
0000000000000010: &nbsp; 00000000 00000000 47be0500 0000††††††........G¾.... &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x7e Length 38<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 38 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4A07E<br />
<br />
0000000000000000: &nbsp; 70000d00 02000000 d1530384 9d040000 †p.......ÑS..... <br />
0000000000000010: &nbsp; 01001800 54455354 00000000 00000000 †....TEST........ <br />
0000000000000020: &nbsp; 47be0500 0000††††††††††††††††††††††††G¾.... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) &nbsp;<br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 52 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 2 Offset 0x14 Length 208 Length (physical) 208<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST<br />
<br />
Slot 52 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 52 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (350070284e19) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>Now that the versioning information has been added it is time to re-run the delete test to see what effect a delete and subsequent rollback has. Here is the code for this test:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON<span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">BEGIN</span> <span style="color: #0000FF;">TRANSACTION</span><br />
<br />
<span style="color: #0000FF;">DELETE</span> &nbsp;dbo.<span style="color: #202020;">TestTable</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; id <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">156</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">ROLLBACK</span><br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">156</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>The first set of DBCC PAGE results shows exactly what I expected. The record in slot 0 is marked as a GHOST_DATA_RECORD and the version pointer is now populated with a pointer to a location in TempDB. <em>Note: You can run DBCC PAGE to look at that record in TempDB if the transaction is still open. It is beyond the scope of this post so I will not cover it here but definitely interesting to look at.</em> What has not changed is that m_freeCnt is still 680. There was no change in record size or space usage.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:156)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6080<br />
<br />
bpage = 0x0000000090182000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:156)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 35111<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x432159bb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x0000000090182000<br />
<br />
m_pageId = (1:156) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x2000<br />
m_objId (AllocUnitId.idObj) = 29 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039828480 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038910976 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:160)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 680<br />
m_freeData = 7474 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:435:35)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:992) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 1<br />
m_tornBits = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x68 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x1d14 Length 30<br />
<br />
Record Type = GHOST_DATA_RECORD &nbsp; &nbsp; &nbsp;Record Attributes = &nbsp;NULL_BITMAP VERSIONING_INFO<br />
Record Size = 30 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BD14<br />
<br />
0000000000000000: &nbsp; 5c000d00 01000000 d0530384 9d040000 †.......ÐS..... <br />
0000000000000010: &nbsp; c8010000 01000100 a0bf0500 0000††††††È....... ¿.... &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376736<br />
&nbsp; &nbsp; Version Pointer: (file 1 page 456 currentSlotId 1)<br />
<br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x1cee Length 38<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 38 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BCEE<br />
<br />
0000000000000000: &nbsp; 70000d00 02000000 d1530384 9d040000 †p.......ÑS..... <br />
0000000000000010: &nbsp; 01001800 54455354 00000000 00000000 †....TEST........ <br />
0000000000000020: &nbsp; 47be0500 0000††††††††††††††††††††††††G¾.... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) <br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
KeyHashValue = (3400154ff2a1) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 52 Offset 0x1bfc Length 242<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 242 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Memory Dump @0x0000000018A4BBFC<br />
<br />
0000000000000000: &nbsp; 70000d00 35000000 d0530384 9d040000 †p...5...ÐS..... <br />
0000000000000010: &nbsp; 0100e400 54455354 54455354 54455354 †..ä.TESTTESTTEST <br />
0000000000000020: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000030: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000040: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000050: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000060: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000070: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000080: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000090: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000A0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000B0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000C0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000D0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000E0: &nbsp; 54455354 00000000 00000000 47be0500 †TEST........G¾.. <br />
00000000000000F0: &nbsp; 0000†††††††††††††††††††††††††††††††††.. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 52 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 2 Offset 0x14 Length 208 Length (physical) 208<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST<br />
<br />
Slot 52 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 52 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (350070284e19) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>The second DBCC PAGE result shows that the record in slot 0 is no longer a GHOST_DATA_RECORD and the version pointer has reverted to Null. The m_freeCnt is still 680.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:156)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6080<br />
<br />
bpage = 0x0000000090182000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:156)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 35512<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x432159bb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x0000000090182000<br />
<br />
m_pageId = (1:156) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x6000<br />
m_objId (AllocUnitId.idObj) = 29 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039828480 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038910976 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:160)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 680<br />
m_freeData = 7504 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:435:38)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:992) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 0<br />
m_tornBits = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x60 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x1d32 Length 30<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VERSIONING_INFO<br />
Record Size = 30 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BD32<br />
<br />
0000000000000000: &nbsp; 50000d00 01000000 d0530384 9d040000 †P.......ÐS..... <br />
0000000000000010: &nbsp; 00000000 00000000 47be0500 0000††††††........G¾.... &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x1cee Length 38<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 38 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BCEE<br />
<br />
0000000000000000: &nbsp; 70000d00 02000000 d1530384 9d040000 †p.......ÑS..... <br />
0000000000000010: &nbsp; 01001800 54455354 00000000 00000000 †....TEST........ <br />
0000000000000020: &nbsp; 47be0500 0000††††††††††††††††††††††††G¾.... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 2 Offset 0xa4 Length 42<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 42 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4A0A4<br />
<br />
0000000000000000: &nbsp; 70000d00 03000000 d0530384 9d040000 †p.......ÐS..... <br />
0000000000000010: &nbsp; 01001c00 54455354 54455354 00000000 †....TESTTEST.... <br />
0000000000000020: &nbsp; 00000000 47be0500 0000†††††††††††††††....G¾.... &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 2 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 2 Column 2 Offset 0x14 Length 8 Length (physical) 8<br />
<br />
varchar_value = TESTTEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 2 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 2 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 2 Offset 0x0 Length 0 Length (physical) 0<br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
KeyHashValue = (3400154ff2a1) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 52 Offset 0x1bfc Length 242<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 242 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Memory Dump @0x0000000018A4BBFC<br />
<br />
0000000000000000: &nbsp; 70000d00 35000000 d0530384 9d040000 †p...5...ÐS..... <br />
0000000000000010: &nbsp; 0100e400 54455354 54455354 54455354 †..ä.TESTTESTTEST <br />
0000000000000020: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000030: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000040: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000050: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000060: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000070: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000080: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
0000000000000090: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000A0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000B0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000C0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000D0: &nbsp; 54455354 54455354 54455354 54455354 †TESTTESTTESTTEST <br />
00000000000000E0: &nbsp; 54455354 00000000 00000000 47be0500 †TEST........G¾.. <br />
00000000000000F0: &nbsp; 0000†††††††††††††††††††††††††††††††††.. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 52 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 2 Offset 0x14 Length 208 Length (physical) 208<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST<br />
<br />
Slot 52 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 52 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (350070284e19) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<p>I am feeling pretty good about my results so far but I want to do a final test to rule out any effect from the use of transactions in my testing. Here is the final test:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON<span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DELETE</span> &nbsp;dbo.<span style="color: #202020;">TestTable</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; id <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> PAGE<span style="color: #808080;">&#40;</span>RecordSizeTest, <span style="color: #000;">1</span>, <span style="color: #000;">156</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>The DBCC PAGE results from this test confirm that transactions have not impacted the test cases above. The results below do depend on how the test is run though. I ran both the delete and DBCC PAGE as a single command and was able to see the ghost record in slot 0 and m_freeCnt was still 680. If I had run the statements individually I would most likely have seen that the ghost cleanup process had removed the record in slot 0 with the row that had been in slot 1 now showing in slot 0. The m_freeCnt would also have been updated to be 712, reflecting the removal of the record.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PAGE: (1:156)<br />
<br />
<br />
BUFFER:<br />
<br />
<br />
BUF @0x0000000090FC6080<br />
<br />
bpage = 0x0000000090182000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bhash = 0x0000000000000000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bpageno = (1:156)<br />
bdbid = 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;breferences = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUse1 = 35886<br />
bstat = 0x6c0000b &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;blog = 0x432159bb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bnext = 0x0000000000000000<br />
<br />
PAGE HEADER:<br />
<br />
<br />
Page @0x0000000090182000<br />
<br />
m_pageId = (1:156) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_headerVersion = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_type = 1<br />
m_typeFlagBits = 0x4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_level = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_flagBits = 0x2000<br />
m_objId (AllocUnitId.idObj) = 29 &nbsp; &nbsp; m_indexId (AllocUnitId.idInd) = 256 &nbsp;<br />
Metadata: AllocUnitId = 72057594039828480 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Metadata: PartitionId = 72057594038910976 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Metadata: IndexId = 1<br />
Metadata: ObjectId = 2105058535 &nbsp; &nbsp; &nbsp;m_prevPage = (0:0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_nextPage = (1:160)<br />
pminlen = 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_slotCnt = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_freeCnt = 680<br />
m_freeData = 7504 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_reservedCnt = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_lsn = (34:435:43)<br />
m_xactReserved = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_xdesId = (0:993) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_ghostRecCnt = 1<br />
m_tornBits = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Allocation Status<br />
<br />
GAM (1:2) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SGAM (1:3) = ALLOCATED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
PFS (1:1) = 0x68 MIXED_EXT ALLOCATED &nbsp; 0_PCT_FULL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DIFF (1:6) = CHANGED<br />
ML (1:7) = NOT MIN_LOGGED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Offset 0x1d32 Length 30<br />
<br />
Record Type = GHOST_DATA_RECORD &nbsp; &nbsp; &nbsp;Record Attributes = &nbsp;NULL_BITMAP VERSIONING_INFO<br />
Record Size = 30 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BD32<br />
<br />
0000000000000000: &nbsp; 5c000d00 01000000 d0530384 9d040000 †.......ÐS..... <br />
0000000000000010: &nbsp; d0010000 01000000 81c00500 0000††††††Ð........À.... &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376961<br />
&nbsp; &nbsp; Version Pointer: (file 1 page 464 currentSlotId 0)<br />
<br />
<br />
Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Column 2 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
varchar_value = &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 0 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 0 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (010086470766) &nbsp; &nbsp; &nbsp; &nbsp;<br />
Slot 1 Offset 0x1cee Length 38<br />
<br />
Record Type = PRIMARY_RECORD &nbsp; &nbsp; &nbsp; &nbsp; Record Attributes = &nbsp;NULL_BITMAP VARIABLE_COLUMNS VERSIONING_INFO<br />
Record Size = 38 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Memory Dump @0x0000000018A4BCEE<br />
<br />
0000000000000000: &nbsp; 70000d00 02000000 d1530384 9d040000 †p.......ÑS..... <br />
0000000000000010: &nbsp; 01001800 54455354 00000000 00000000 †....TEST........ <br />
0000000000000020: &nbsp; 47be0500 0000††††††††††††††††††††††††G¾.... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 1 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 2 Offset 0x14 Length 4 Length (physical) 4<br />
<br />
varchar_value = TEST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 1 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 1 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (020068e8b274) &nbsp;<br />
&lt;snip&gt;<br />
.<br />
.<br />
.<br />
&lt;/snip&gt;<br />
Version Information = <br />
&nbsp; &nbsp; Transaction Timestamp: 376391<br />
&nbsp; &nbsp; Version Pointer: Null<br />
<br />
<br />
Slot 52 Column 1 Offset 0x4 Length 4 Length (physical) 4<br />
<br />
id = 53 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 2 Offset 0x14 Length 208 Length (physical) 208<br />
<br />
varchar_value = TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTT<br />
ESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST<br />
<br />
Slot 52 Column 3 Offset 0x8 Length 1 (Bit position 0)<br />
<br />
bit_value = 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
Slot 52 Column 4 Offset 0x9 Length 4 Length (physical) 4<br />
<br />
create_date = 2010-05-28 14:11:00.000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
Slot 52 Offset 0x0 Length 0 Length (physical) 0<br />
<br />
KeyHashValue = (350070284e19) &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
<br />
DBCC execution completed. If DBCC printed error messages, contact your system administrator.</div></td></tr></tbody></table></div>
<h2>Conclusion</h2>
<p>I started out with a theory that rebuilding the indexes in a database with ONLINE=ON will prevent unexpected space usage due to large update or delete operations in a database that has Read Committed Snapshot Isolation enabled. I feel that through my tests I have shown that adding the versioning information at the time of reindexing is a viable alternative to keeping extra free space in a database. It is definitely a great alternative to dealing with production issues caused by a full database. Like anything else this solution is not perfect, but if I know there is a big delete coming, I will definitely make sure the indexes on the impacted tables are rebuilt with ONLINE=ON or that I have included extra space via FILL_FACTOR. Most importantly, I know to expect growth from large update or delete operations and can manage accordingly in the way the database is set up and the number of records impacted by each pass over the data.</p>
<p>Thank you for sticking with me to the end of this long post. I hope it was as informative to read as it was to write. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=IHEK7aAAoQ4:zvWa8GnsXHE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=IHEK7aAAoQ4:zvWa8GnsXHE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=IHEK7aAAoQ4:zvWa8GnsXHE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=IHEK7aAAoQ4:zvWa8GnsXHE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=IHEK7aAAoQ4:zvWa8GnsXHE:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/IHEK7aAAoQ4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/06/why-would-a-delete-make-my-database-grow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/06/why-would-a-delete-make-my-database-grow/</feedburner:origLink></item>
		<item>
		<title>What is a Good Way to Run CheckDB on a VLDB?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/_lni5hB-5W0/</link>
		<comments>http://adventuresinsql.com/2010/05/what-is-a-good-way-to-run-checkdb-on-a-vldb/#comments</comments>
		<pubDate>Fri, 21 May 2010 19:25:06 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[SSC]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=356</guid>
		<description><![CDATA[Today's script is one that I wrote based on the logic outlined in a post by Paul Randal. This script is written for SQL 2000 but, as Paul notes, the logic will work on SQL 2005. <a href="http://adventuresinsql.com/2010/05/what-is-a-good-way-to-run-checkdb-on-a-vldb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Today&#8217;s script is one that I wrote based on the logic outlined in this <a href="http://sqlskills.com/BLOGS/PAUL/post/CHECKDB-From-Every-Angle-Consistency-Checking-Options-for-a-VLDB.aspx">post</a> by Paul Randal (<a href="http://sqlskills.com/BLOGS/PAUL">Blog</a>|<a href="http://www.twitter.com/PaulRandal">Twitter</a>). This script is written for SQL 2000 but, as Paul notes, the logic will work on SQL 2005.</p>
<h2>The Script</h2>
<p>This stored procedure stays pretty true to the logic outlined in Paul&#8217;s post so I will just cover the differences here. The first thing to notice is that the parameters passed into the procedure are the days of the week that different portions of the check should run, the maximum run time in minutes and whether or not to print debug messages. The stored procedure then parses the input strings and runs CHECKALLOCs and CHECKCATALOGs if requested. </p>
<p>If tables should be checked today a little more work is necessary. I decided to use a utility database to hold work tables for my custom scripts called DBADB. The first part of performing a table check is to see if a work table already exists in the database. If the table does not exist then one is created and loaded with a list of all tables in the database. After the table is loaded, the process begins looping through the table, checking that the run time has not been exceeded then running checktable on each table. This continues until the table list has been processed or time runs out. If time runs out then the process picks up where it left off next time the table check starts to make sure all tables are eventually checked before starting over again.</p>
<p>Here is the script:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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>sp_dba_checkdb_vldb<span style="color: #808080;">&#93;</span> @days_to_run_checkalloc <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'1,4'</span>, @days_to_run_checkcatalog <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'1'</span>, @days_to_run_checktable <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'1,2,3,4,5,6,7'</span>, @max_minutes_to_run <span style="color: #0000FF;">int</span> <span style="color: #808080;">=</span> <span style="color: #000;">360</span>, @debug_flag <span style="color: #0000FF;">bit</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<span style="color: #0000FF;">AS</span><br />
<br />
&nbsp;<span style="color: #0000FF;">BEGIN</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @date_part_search_string&nbsp; &nbsp; <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @start_time &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">datetime</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @sql_text &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @current_object_id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">int</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @date_part_search_string <span style="color: #808080;">=</span> <span style="color: #FF0000;">'%'</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>dw, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</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;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'%'</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @start_time <span style="color: #808080;">=</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span>@date_part_search_string, @days_to_run_checkalloc<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running DBCC CHECKALLOC'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DBCC</span> CHECK<span style="color: #808080;">ALL</span>OC<br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span>@date_part_search_string, @days_to_run_checkcatalog<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running DBCC CHECKCATALOG'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DBCC</span> CHECKCATALOG <br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span>@date_part_search_string, @days_to_run_checktable<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @control_table&nbsp; <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">500</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @control_table <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_dbcc_checktable_worklist'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">EXISTS</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>DBADB<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>sysobjects<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">WHERE</span> name <span style="color: #808080;">=</span> @control_table<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SELECT DISTINCT <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i.id,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CAST(NULL AS datetime) AS run_date_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INTO&nbsp; &nbsp; [DBADB].[dbo].'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@control_table<span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM&nbsp; &nbsp; sysindexes i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN sysobjects o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON i.id = o.id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; o.type != '</span><span style="color: #FF0000;">'TF'</span><span style="color: #FF0000;">''</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span>&nbsp; @sql_text<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">'CREATE CLUSTERED INDEX IX_'</span> <span style="color: #808080;">+</span> @control_table <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_id_run_date_time ON [DBADB].[dbo].'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@control_table<span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' (id, run_date_time)'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span>&nbsp; @sql_text<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">' &nbsp; SELECT&nbsp; TOP 1 @current_object_id = c.id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM&nbsp; &nbsp; [DBADB].[dbo].['</span> <span style="color: #808080;">+</span> @control_table <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] c<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN sysobjects o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON c.id = o.id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; c.run_date_time IS NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND o.type != '</span><span style="color: #FF0000;">'TF'</span><span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_text, N<span style="color: #FF0000;">'@current_object_id int OUTPUT'</span>, @current_object_id <span style="color: #808080;">=</span> @current_object_id <span style="color: #0000FF;">OUTPUT</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: @current_object_id = '</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@current_object_id <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">'NULL'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHILE</span> &nbsp; @current_object_id <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #808080;">AND</span> <span style="color: #FF00FF;">DATEADD</span><span style="color: #808080;">&#40;</span>mi, @max_minutes_to_run, @start_time<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> @current_object_id <span style="color: #808080;">=</span> <span style="color: #808080;">NULL</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">' &nbsp; SELECT&nbsp; TOP 1 @current_object_id = c.id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM&nbsp; &nbsp; [DBADB].[dbo].['</span> <span style="color: #808080;">+</span> @control_table <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] c<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN sysobjects o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON c.id = o.id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; c.run_date_time IS NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND o.type != '</span><span style="color: #FF0000;">'TF'</span><span style="color: #FF0000;">''</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_text, N<span style="color: #FF0000;">'@current_object_id int OUTPUT'</span>, @current_object_id <span style="color: #808080;">=</span> @current_object_id <span style="color: #0000FF;">OUTPUT</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: @current_object_id = '</span> <span style="color: #808080;">+</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@current_object_id <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">'NULL'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running DBCC CHECKTABLE('</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@current_object_id <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">')'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DBCC</span> CHECKTABLE<span style="color: #808080;">&#40;</span>@current_object_id<span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">' &nbsp; UPDATE&nbsp; [DBADB].[dbo].['</span> <span style="color: #808080;">+</span> @control_table <span style="color: #808080;">+</span> <span style="color: #FF0000;">']<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET &nbsp; &nbsp; run_date_time = GETDATE()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; id = @current_object_id'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @sql_text, N<span style="color: #FF0000;">'@current_object_id int OUTPUT'</span>, @current_object_id <span style="color: #808080;">=</span> @current_object_id <span style="color: #0000FF;">OUTPUT</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @current_object_id <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'Ran out of work to do...cleaning up and shutting down.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #808080;">EXISTS</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> <span style="color: #808080;">&#91;</span>DBADB<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>sysobjects<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">WHERE</span> name <span style="color: #808080;">=</span> @control_table<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @sql_text <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DROP TABLE [DBADB].[dbo].'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>@control_table<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @debug_flag <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'DEBUG: Running sql command: ['</span> <span style="color: #808080;">+</span> @sql_text <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span>&nbsp; @sql_text<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'Ran out of time...shutting down.'</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">END</span><br />
&nbsp;<span style="color: #0000FF;">END</span><br />
GO</div></td></tr></tbody></table></div>
<h2>Conclusion</h2>
<p>As usual, I hope you find this script helpful. Please let me know if you run into any issues with it or know a better way to do the same thing. Please keep in mind that scripts from the internet are like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=_lni5hB-5W0:_B07g0XMPic:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=_lni5hB-5W0:_B07g0XMPic:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=_lni5hB-5W0:_B07g0XMPic:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=_lni5hB-5W0:_B07g0XMPic:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=_lni5hB-5W0:_B07g0XMPic:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/_lni5hB-5W0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/05/what-is-a-good-way-to-run-checkdb-on-a-vldb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/05/what-is-a-good-way-to-run-checkdb-on-a-vldb/</feedburner:origLink></item>
		<item>
		<title>How Do I Move SQL Database Files Around?</title>
		<link>http://feedproxy.google.com/~r/AdventuresInSql/~3/hOGm6pm1C9U/</link>
		<comments>http://adventuresinsql.com/2010/05/how-do-i-move-sql-database-files-around/#comments</comments>
		<pubDate>Tue, 11 May 2010 01:08:58 +0000</pubDate>
		<dc:creator>David Levy</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[move]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[online]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[SSC]]></category>
		<category><![CDATA[xp_cmdshell]]></category>

		<guid isPermaLink="false">http://adventuresinsql.com/?p=336</guid>
		<description><![CDATA[Here is a script that will generate a script to move database files around in SQL 2005/2008. <a href="http://adventuresinsql.com/2010/05/how-do-i-move-sql-database-files-around/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Today&#8217;s script is one that I had not planned on blogging so soon but since <a href="http://www.sqlskills.com/BLOGS/PAUL/post/TechNet-Magazine-May-2010-SQL-QA-column.aspx">Paul Randal just talked about moving SQL Server files around for TechNet Magazine</a>, it seemed like a good time to break this one out.</p>
<h2>The Script</h2>
<p>This script is a little different in that it is a script that creates a script, a &#8220;turducken&#8221; script if you will. The idea here is to run this script and let it <b>output to text</b> then take those results, paste them into a new window, <b>review the resulting script</b> and maybe even run it. </p>
<p>The script starts out by getting the default data and log file locations from SQL Server by checking the registry, using a method learned by watching Profiler while checking the location with Management Studio. (I often comment out these lines to change to specific locations.) The script then begins building the string to output by creating the command to turn xp_cmdshell on. A lot of people, including me, have a policy against xp_cmdshell being turned on on their servers but in cases like this where it is turned on to be used and turned right back off I feel I can get away with it. The next step is to create alter database scripts to take the databases offline. Next, the alter database statements and DOS file move commands are created. The command to set the database online is then added and finally, xp_cmdshell is turned back off.</p>
<p><em>Updated 07/14/2010 to replace move commands with copy to make sure the files are still good before they are deleted. This does add manual cleanup but the trade off is not having to find out how good your last backup is. Thanks to Paul Randal (<a href="http://www.SQLskills.com/blogs/paul">Blog</a>|<a href="http://www.twitter.com/PaulRandal">Twitter</a>) and Buck Woody (<a href="http://buckwoody.com">Blog</a>|<a href="http://twitter.com/buckwoody">Twitter</a>) for pointing this out.</em></p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @file_path &nbsp;<span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">520</span><span style="color: #808080;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @log_path &nbsp; <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">520</span><span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">xp_instance_regread</span> N<span style="color: #FF0000;">'HKEY_LOCAL_MACHINE'</span>, N<span style="color: #FF0000;">'SoftwareMicrosoftMSSQLServerMSSQLServer'</span>, N<span style="color: #FF0000;">'DefaultData'</span>, @file_path <span style="color: #0000FF;">OUTPUT</span><br />
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">xp_instance_regread</span> N<span style="color: #FF0000;">'HKEY_LOCAL_MACHINE'</span>, N<span style="color: #FF0000;">'SoftwareMicrosoftMSSQLServerMSSQLServer'</span>, N<span style="color: #FF0000;">'DefaultLog'</span>, @log_path <span style="color: #0000FF;">OUTPUT</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'EXEC sp_configure '</span><span style="color: #FF0000;">'show advanced options'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'1'</span><span style="color: #FF0000;">'<br />
GO<br />
RECONFIGURE<br />
GO<br />
EXEC sp_configure '</span><span style="color: #FF0000;">'xp_cmdshell'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'1'</span><span style="color: #FF0000;">'<br />
GO<br />
RECONFIGURE<br />
GO'</span><br />
<br />
<span style="color: #0000FF;">SELECT</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>mf.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] SET OFFLINE WITH ROLLBACK IMMEDIATE<br />
GO<br />
ALTER DATABASE ['</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>mf.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] MODIFY FILE (NAME = ['</span> <span style="color: #808080;">+</span> mf.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'], FILENAME = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @file_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.mdf'</span><span style="color: #FF0000;">') <br />
GO<br />
ALTER DATABASE ['</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>mf.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] MODIFY FILE (NAME = ['</span> <span style="color: #808080;">+</span> mf2.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'], FILENAME = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @log_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf2.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.ldf'</span><span style="color: #FF0000;">') <br />
GO<br />
EXEC xp_cmdshell '</span><span style="color: #FF0000;">'copy /Y &quot;'</span> <span style="color: #808080;">+</span> mf.<span style="color: #202020;">physical_name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'&quot; &quot;'</span> <span style="color: #808080;">+</span> @file_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.mdf&quot;'</span><span style="color: #FF0000;">'<br />
GO <br />
EXEC xp_cmdshell '</span><span style="color: #FF0000;">'copy /Y &quot;'</span> <span style="color: #808080;">+</span> mf2.<span style="color: #202020;">physical_name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'&quot; &quot;'</span> <span style="color: #808080;">+</span> @log_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf2.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.ldf&quot;'</span><span style="color: #FF0000;">'<br />
GO <br />
ALTER DATABASE ['</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>mf.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] SET ONLINE<br />
GO<br />
<br />
'</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">master_files</span> mf<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> sys.<span style="color: #202020;">master_files</span> mf2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> mf.<span style="color: #202020;">database_id</span> <span style="color: #808080;">=</span> mf2.<span style="color: #202020;">database_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>mf.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'master'</span>, <span style="color: #FF0000;">'model'</span>, <span style="color: #FF0000;">'msdb'</span>, <span style="color: #FF0000;">'tempdb'</span><span style="color: #808080;">&#41;</span> and mf.<span style="color: #202020;">type_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ROWS'</span> and mf.<span style="color: #FF00FF;">file_id</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span> and mf2.<span style="color: #202020;">type_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span><br />
<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span>mf.<span style="color: #202020;">physical_name</span> <span style="color: #808080;">!=</span> @file_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.mdf'</span> <span style="color: #808080;">OR</span> mf2.<span style="color: #202020;">physical_name</span> <span style="color: #808080;">!=</span> @log_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> mf2.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.ldf'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">order</span> <span style="color: #0000FF;">by</span> mf.<span style="color: #202020;">name</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'EXEC sp_configure '</span><span style="color: #FF0000;">'xp_cmdshell'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'0'</span><span style="color: #FF0000;">'<br />
GO<br />
RECONFIGURE<br />
GO<br />
EXEC sp_configure '</span><span style="color: #FF0000;">'show advanced options'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'0'</span><span style="color: #FF0000;">'<br />
GO<br />
RECONFIGURE<br />
GO'</span></div></td></tr></tbody></table></div>
<h2>Would this Work for TempDB?</h2>
<p>Yes and no. The resulting script can be used to alter the location of TempDB but SQL Server must be stopped and started to move the files. There would also have to be manual cleanup in that the old TempDB files would have to be deleted.</p>
<h2>Would this Work for System Databases other than TempDB?</h2>
<p>No. There is a lot involved in moving a system database. Detailed instructions can be found here: <a href="http://msdn.microsoft.com/en-us/library/ms345408.aspx">http://msdn.microsoft.com/en-us/library/ms345408.aspx</a></p>
<h2>Conclusion</h2>
<p>As usual, I hope you find this script helpful. Please let me know if you run into any issues with it or know a better way to do the same thing. Please keep in mind that scripts from the internet are like Halloween candy, inspect before consumption. I offer no warranty beyond a sympathetic ear if you should run into any issues.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=hOGm6pm1C9U:2U4KfNHw34E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=hOGm6pm1C9U:2U4KfNHw34E:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=hOGm6pm1C9U:2U4KfNHw34E:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/AdventuresInSql?a=hOGm6pm1C9U:2U4KfNHw34E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/AdventuresInSql?i=hOGm6pm1C9U:2U4KfNHw34E:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/AdventuresInSql/~4/hOGm6pm1C9U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://adventuresinsql.com/2010/05/how-do-i-move-sql-database-files-around/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://adventuresinsql.com/2010/05/how-do-i-move-sql-database-files-around/</feedburner:origLink></item>
	</channel>
</rss>
