SQL Server: Which tables are storing the most physical data?

by Stephen Horsfield 9. January 2008 15:16

Overview

Following on from my previous post, here's a quick way to find out which data tables are using the most disk space...

References

Solution

SELECT o.name AS table_name, SUM(au.data_pages) as pages,
       ((SUM(au.data_pages) * 8192) / (1024 * 1024)) AS MB
FROM sys.allocation_units AS au
     JOIN sys.partitions AS p ON au.container_id = p.partition_id
     JOIN sys.tables AS o ON p.object_id = o.object_id
     JOIN sys.indexes AS i ON p.index_id = i.index_id AND i.object_id = p.object_id
GROUP BY o.name
ORDER BY pages desc, o.name
GO

Versions

Metadata

Tags:

IT Management | Software Development | SQL Server

Comments

4/5/2009 8:34:51 AM #

Doesn't appear to give the correct result where there is a large amount of data in fields of type "image". We use these to store pdf's and the like and all the methods for determining size all seem to fail on this field.

Rob von Nesselrode |

4/6/2009 7:11:17 AM #

No, this method won't work on LOBs as these are not stored in the same way.  You can determine the amount of data in LOB columns (image, text, ntext and the 2005+ var...(max) types) in other ways, such as using the DATALENGTH function

Stephen Horsfield |

4/6/2009 7:16:11 AM #

See also the system view sys.tables and the column "lob_data_space_id" in SQL Server 2005+.  Sorry I can't give a fully worked example at the moment.

Stephen Horsfield |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar