Tuesday, 23 October 2012

List all Objects per Filegroup

The following query can be used to list all obejcts per filegroup including the allocated data size.
SELECT ds.name AS DataSpaceName ,au.type_desc AS AllocationDesc ,au.total_pages / 128 AS TotalSizeMB ,au.used_pages / 128 AS UsedSizeMB ,au.data_pages / 128 AS DataSizeMB ,sch.name AS schemaName ,obj.type_desc AS ObjectType ,obj.name AS ObjectName ,idx.type_desc AS IndexType ,idx.name AS IndexName FROM sys.data_spaces AS ds INNER JOIN sys.allocation_units AS au ON ds.data_space_id = au.data_space_id INNER JOIN sys.partitions AS PA ON (au.type IN (1, 3) AND au.container_id = PA.hobt_id) OR (au.type = 2 AND au.container_id = PA.partition_id) INNER JOIN sys.objects AS obj ON PA.object_id = obj.object_id INNER JOIN sys.schemas AS sch ON obj.schema_id = sch.schema_id LEFT JOIN sys.indexes AS idx ON PA.object_id = IDX.object_id AND PA.index_id = idx.index_id WHERE obj.type_desc NOT IN('SYSTEM_TABLE', 'INTERNAL_TABLE') ORDER BY ds.name ,sch.name ,obj.name ,idx.name

No comments:

Post a Comment