Determine Size of a Table in SQL Server
Ever wonder how big a table really is in your database? You know there are a million rows in the table, but how much space is that really taking?
SQL Server provides a built-in stored procedure that you can run to easily show the size of a table, including the size of the indexes… which might surprise you.
Syntax:
sp_spaceused ‘Tablename’
Here’s an example of it in action:
Highly useful stuff. It’s always interesting to see that the indexes are bigger than the actual data.

Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


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’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 ‘unused’ value), run a “DBCC UPDATEUSAGE” command against the table in question before running sp_spacesued (or against the entire database if you have time and aren’t worried about stepping on anyone’s toes).
This can automatically be done as an optional parameter within sp_spaceused…
e.g. sp_spaceused ‘Orders’,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 (’InsertdDbNameHere’)
For a specific table:
DBCC UPDATEUSAGE (’InsertdDbNameHere’,'InsertdTableNameHere’)
You can always check BOL for all the details on DBCC UPDATEUSAGE
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?
I just found this, it returns spaceused for each table:
EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused ‘?’”
Charles sp_helpdb
Rick – that is one of the most useful sql server commands of all time. You are the greatest.
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
Bah, it got cut off, here is the rest:
When p.index_id
When p.index_id
(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=’mittra’
group by t.[name]) as subselect