<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: MSSQL Table Size for all tables</title>
	<atom:link href="http://www.keyboardface.com/wp-404-handler.php/archives/2007/06/12/mssql-table-size-for-all-tables/feed/?404;http://www.keyboardface.com:80/archives/2007/06/12/mssql-table-size-for-all-tables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/</link>
	<description>when you find QWERTY imprinted on your cheek - it's time to go to bed.</description>
	<lastBuildDate>Mon, 15 Mar 2010 14:14:18 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dino</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-55373</link>
		<dc:creator>Dino</dc:creator>
		<pubDate>Wed, 11 Mar 2009 12:16:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-55373</guid>
		<description>Tnx!</description>
		<content:encoded><![CDATA[<p>Tnx!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Stouffer</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-36342</link>
		<dc:creator>Mark Stouffer</dc:creator>
		<pubDate>Thu, 13 Nov 2008 20:06:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-36342</guid>
		<description>Wow, thanks. I was just about to write this myself. The space used is great but I don&#039;t want to run it for every table.</description>
		<content:encoded><![CDATA[<p>Wow, thanks. I was just about to write this myself. The space used is great but I don&#8217;t want to run it for every table.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoli</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-32855</link>
		<dc:creator>Zoli</dc:creator>
		<pubDate>Fri, 17 Oct 2008 22:10:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-32855</guid>
		<description>Thank for the code. I&#039;ve made some modifications for better performance and the different schema usage:

declare @tablename varchar(100),@tableschema varchar(100), @tt varchar(100)
DECLARE @partitions bigint;
declare @Space table (
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)
)

select s.name as tableschema, o.name as tablename
into #work_to_do
	FROM sys.objects as o  
	JOIN sys.schemas as s ON s.schema_id = o.schema_id 
	WHERE o.type_desc = &#039;USER_TABLE&#039;
	order by o.name

DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;

OPEN partitions;

WHILE (1=1)
    BEGIN;
        FETCH NEXT
           FROM partitions
           INTO @tableschema, @tablename;
        IF @@FETCH_STATUS &lt; 0 BREAK;
		SET @tt = @tableschema + N&#039;.&#039; + @tablename 
		insert into @Space exec sp_spaceused @tt
	END;
update @Space set data = replace(data, &#039; KB&#039;,&#039;&#039;)
update @Space set data = convert(int, data)/1000

update @Space set reserved = replace(reserved, &#039; KB&#039;,&#039;&#039;)
update @Space set reserved = convert(int, reserved)/1000

update @Space set index_size = replace(index_size, &#039; KB&#039;,&#039;&#039;)
update @Space set index_size = convert(int, index_size)/1000

update @Space set unused = replace(unused, &#039; KB&#039;,&#039;&#039;)
update @Space set unused = convert(int, unused)/1000

CLOSE partitions;
DEALLOCATE partitions;
drop table #work_to_do

select top 500 * from @Space order by convert(int, data) desc</description>
		<content:encoded><![CDATA[<p>Thank for the code. I&#8217;ve made some modifications for better performance and the different schema usage:</p>
<p>declare @tablename varchar(100),@tableschema varchar(100), @tt varchar(100)<br />
DECLARE @partitions bigint;<br />
declare @Space table (<br />
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)<br />
)</p>
<p>select s.name as tableschema, o.name as tablename<br />
into #work_to_do<br />
	FROM sys.objects as o<br />
	JOIN sys.schemas as s ON s.schema_id = o.schema_id<br />
	WHERE o.type_desc = &#8216;USER_TABLE&#8217;<br />
	order by o.name</p>
<p>DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;</p>
<p>OPEN partitions;</p>
<p>WHILE (1=1)<br />
    BEGIN;<br />
        FETCH NEXT<br />
           FROM partitions<br />
           INTO @tableschema, @tablename;<br />
        IF @@FETCH_STATUS &lt; 0 BREAK;<br />
		SET @tt = @tableschema + N&#8217;.&#8217; + @tablename<br />
		insert into @Space exec sp_spaceused @tt<br />
	END;<br />
update @Space set data = replace(data, &#8216; KB&#8217;,&#8221;)<br />
update @Space set data = convert(int, data)/1000</p>
<p>update @Space set reserved = replace(reserved, &#8216; KB&#8217;,&#8221;)<br />
update @Space set reserved = convert(int, reserved)/1000</p>
<p>update @Space set index_size = replace(index_size, &#8216; KB&#8217;,&#8221;)<br />
update @Space set index_size = convert(int, index_size)/1000</p>
<p>update @Space set unused = replace(unused, &#8216; KB&#8217;,&#8221;)<br />
update @Space set unused = convert(int, unused)/1000</p>
<p>CLOSE partitions;<br />
DEALLOCATE partitions;<br />
drop table #work_to_do</p>
<p>select top 500 * from @Space order by convert(int, data) desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-24262</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 04 Jul 2008 15:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-24262</guid>
		<description>That&#039;s great. Thanks</description>
		<content:encoded><![CDATA[<p>That&#8217;s great. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richie</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-24251</link>
		<dc:creator>Richie</dc:creator>
		<pubDate>Fri, 04 Jul 2008 13:16:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-24251</guid>
		<description>BTW: If you are only interested in Tables that contain data/aren&#039;t empty, exchange the last select statement with this one:

select * from @Space where data NOT LIKE &#039;0 MB&#039; order by convert(int, replace(data, &#039; MB&#039;, &#039;&#039;)) desc</description>
		<content:encoded><![CDATA[<p>BTW: If you are only interested in Tables that contain data/aren&#8217;t empty, exchange the last select statement with this one:</p>
<p>select * from @Space where data NOT LIKE &#8216;0 MB&#8217; order by convert(int, replace(data, &#8216; MB&#8217;, &#8221;)) desc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richie</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-24250</link>
		<dc:creator>Richie</dc:creator>
		<pubDate>Fri, 04 Jul 2008 13:10:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-24250</guid>
		<description>nice one, thanks!</description>
		<content:encoded><![CDATA[<p>nice one, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alfred Dahl</title>
		<link>http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/comment-page-1/#comment-23718</link>
		<dc:creator>Alfred Dahl</dc:creator>
		<pubDate>Thu, 19 Jun 2008 07:05:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.keyboardface.com/archives/2007/06/12/mssql-table-size-for-all-tables/#comment-23718</guid>
		<description>Thanks,

greatly appreciated - works like a charm :)</description>
		<content:encoded><![CDATA[<p>Thanks,</p>
<p>greatly appreciated &#8211; works like a charm <img src='http://www.keyboardface.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

