<?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: Determine Size of a Table in SQL Server</title>
	<atom:link href="http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/</link>
	<description>Computer Help from your Friendly How-To Geek</description>
	<lastBuildDate>Sun, 22 Nov 2009 18:52:07 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: LNu76</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-68780</link>
		<dc:creator>LNu76</dc:creator>
		<pubDate>Wed, 18 Mar 2009 12:46:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-68780</guid>
		<description>(smaller than sign - why doesnt it take it here?) 2 Then a.data_pages
		Else 0
	END) as pages
 from sys.allocation_units as a Join sys.partitions as p on p.partition_id = a.container_id
		left join sys.internal_tables it on p.object_id = it.object_id
JOIN sys.tables as t on p.object_id=t.object_id
--WHERE t.name=&#039;mittra&#039;
group by t.[name]) as subselect</description>
		<content:encoded><![CDATA[<p>(smaller than sign &#8211; why doesnt it take it here?) 2 Then a.data_pages<br />
		Else 0<br />
	END) as pages<br />
 from sys.allocation_units as a Join sys.partitions as p on p.partition_id = a.container_id<br />
		left join sys.internal_tables it on p.object_id = it.object_id<br />
JOIN sys.tables as t on p.object_id=t.object_id<br />
&#8211;WHERE t.name=&#8217;mittra&#8217;<br />
group by t.[name]) as subselect</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LNu76</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-68778</link>
		<dc:creator>LNu76</dc:creator>
		<pubDate>Wed, 18 Mar 2009 12:45:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-68778</guid>
		<description>When p.index_id </description>
		<content:encoded><![CDATA[<p>When p.index_id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LNu76</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-68469</link>
		<dc:creator>LNu76</dc:creator>
		<pubDate>Wed, 11 Mar 2009 14:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-68469</guid>
		<description>Bah, it got cut off, here is the rest:

		When p.index_id </description>
		<content:encoded><![CDATA[<p>Bah, it got cut off, here is the rest:</p>
<p>		When p.index_id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LNu76</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-68468</link>
		<dc:creator>LNu76</dc:creator>
		<pubDate>Wed, 11 Mar 2009 14:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-68468</guid>
		<description>I tried to use Ricks Tipp, but having 181 Tables in the Database didnt do it much good. Also, his Mechanic with sp_spaceused treated each Table as a standalone query, wich made it impossible to use in an automated Growth-of-Database Statistic.

I stole/borrowed the logic of sp_spaceused and applied it to the following VIEW (wich I now add to a Statistics Table, wich can then be queried in several ways):

SELECT 
TableName, 
NumRows, 
reservedpages *8192/1024 as TotalSpace, 
pages * 8192/1024 as DataSpace, 
(usedpages-pages)*8192/1024 as IndexSpace, 
(reservedpages-usedpages)*8192/1024 as UnusedSpace

FROM (SELECT 
t.[name] as tablename,
avg([rows]) as NumRows,
sum(total_pages) as reservedpages, 
sum(used_pages) as usedpages, 
sum(
	CASE
		When it.internal_type IN (202,204) Then 0
		When a.type  1 Then a.used_pages
		When p.index_id </description>
		<content:encoded><![CDATA[<p>I tried to use Ricks Tipp, but having 181 Tables in the Database didnt do it much good. Also, his Mechanic with sp_spaceused treated each Table as a standalone query, wich made it impossible to use in an automated Growth-of-Database Statistic.</p>
<p>I stole/borrowed the logic of sp_spaceused and applied it to the following VIEW (wich I now add to a Statistics Table, wich can then be queried in several ways):</p>
<p>SELECT<br />
TableName,<br />
NumRows,<br />
reservedpages *8192/1024 as TotalSpace,<br />
pages * 8192/1024 as DataSpace,<br />
(usedpages-pages)*8192/1024 as IndexSpace,<br />
(reservedpages-usedpages)*8192/1024 as UnusedSpace</p>
<p>FROM (SELECT<br />
t.[name] as tablename,<br />
avg([rows]) as NumRows,<br />
sum(total_pages) as reservedpages,<br />
sum(used_pages) as usedpages,<br />
sum(<br />
	CASE<br />
		When it.internal_type IN (202,204) Then 0<br />
		When a.type  1 Then a.used_pages<br />
		When p.index_id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-59584</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Tue, 21 Oct 2008 20:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-59584</guid>
		<description>Rick - that is one of the most useful sql server commands of all time. You are the greatest.</description>
		<content:encoded><![CDATA[<p>Rick &#8211; that is one of the most useful sql server commands of all time. You are the greatest.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanjiv</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-52174</link>
		<dc:creator>Sanjiv</dc:creator>
		<pubDate>Tue, 17 Jun 2008 18:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-52174</guid>
		<description>Charles sp_helpdb</description>
		<content:encoded><![CDATA[<p>Charles sp_helpdb</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-42460</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Thu, 03 Apr 2008 11:54:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-42460</guid>
		<description>I just found this, it returns spaceused for each table:

EXEC sp_MSforeachtable @command1=&quot;EXEC sp_spaceused &#039;?&#039;&quot;</description>
		<content:encoded><![CDATA[<p>I just found this, it returns spaceused for each table:</p>
<p>EXEC sp_MSforeachtable @command1=&#8221;EXEC sp_spaceused &#8216;?&#8217;&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles tucker</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-42408</link>
		<dc:creator>Charles tucker</dc:creator>
		<pubDate>Wed, 02 Apr 2008 16:14:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-42408</guid>
		<description>Thank you, using query analyer and running procedure sp_spaceused is helpful, however, what if your database has close too 100 tables.  Anyway to return the entire database size?</description>
		<content:encoded><![CDATA[<p>Thank you, using query analyer and running procedure sp_spaceused is helpful, however, what if your database has close too 100 tables.  Anyway to return the entire database size?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sMiGuMp</title>
		<link>http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/comment-page-1/#comment-13472</link>
		<dc:creator>sMiGuMp</dc:creator>
		<pubDate>Fri, 04 May 2007 20:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.howtogeek.com/howto/database/determine-size-of-a-table-in-sql-server/#comment-13472</guid>
		<description>While this is a useful command for determining the space allocated to a table, keep in mind that sp_spaceused references the sysindexes system table to get the space attributes and sometimes what&#039;s stored there can get be out of synch with reality.  If you see space numbers that are seemingly out of whack (especially for the &#039;unused&#039; value), run a &quot;DBCC UPDATEUSAGE&quot; command against the table in question before running sp_spacesued (or against the entire database if you have time and aren&#039;t worried about stepping on anyone&#039;s toes).

This can automatically be done as an optional parameter within sp_spaceused...

	e.g. sp_spaceused &#039;Orders&#039;,true


...or as separate commands as shown below.

To update usage stats for the entire current database, the syntax is:
	DBCC UPDATEUSAGE (0)


For a specific, named database:
	DBCC UPDATEUSAGE (&#039;InsertdDbNameHere&#039;)


For a specific table:
	DBCC UPDATEUSAGE (&#039;InsertdDbNameHere&#039;,&#039;InsertdTableNameHere&#039;)


You can always check BOL for all the details on DBCC UPDATEUSAGE</description>
		<content:encoded><![CDATA[<p>While this is a useful command for determining the space allocated to a table, keep in mind that sp_spaceused references the sysindexes system table to get the space attributes and sometimes what&#8217;s stored there can get be out of synch with reality.  If you see space numbers that are seemingly out of whack (especially for the &#8216;unused&#8217; value), run a &#8220;DBCC UPDATEUSAGE&#8221; command against the table in question before running sp_spacesued (or against the entire database if you have time and aren&#8217;t worried about stepping on anyone&#8217;s toes).</p>
<p>This can automatically be done as an optional parameter within sp_spaceused&#8230;</p>
<p>	e.g. sp_spaceused &#8216;Orders&#8217;,true</p>
<p>&#8230;or as separate commands as shown below.</p>
<p>To update usage stats for the entire current database, the syntax is:<br />
	DBCC UPDATEUSAGE (0)</p>
<p>For a specific, named database:<br />
	DBCC UPDATEUSAGE (&#8217;InsertdDbNameHere&#8217;)</p>
<p>For a specific table:<br />
	DBCC UPDATEUSAGE (&#8217;InsertdDbNameHere&#8217;,'InsertdTableNameHere&#8217;)</p>
<p>You can always check BOL for all the details on DBCC UPDATEUSAGE</p>
]]></content:encoded>
	</item>
</channel>
</rss>
