• Jesse,

    Another great article.

    You could make one little add to this - return the number of Indicies for the table by adding

    COUNT( index_id ) As Indicies,

    to your inner join where you create partitions.

    Here is my ammended code to list all tables alphabetically:

    SELECT sys.objects.name AS TableName,

    partitions.Rows, partitions.SizeMB, partitions.Indicies, partitions.SizeMBIndexes, sys.schemas.name AS owner, sys.objects.object_id

    INTO dbo.DDTables

    FROM sys.objects

    INNER JOIN sys.schemas ON sys.objects.schema_id=sys.schemas.schema_id

    INNER JOIN (

    SELECT object_id, SUM(row_count) AS Rows, count( index_id) As Indicies,

    CONVERT(numeric(19,3), CONVERT(numeric(19,3), SUM(CASE WHEN index_id BETWEEN 0 AND 1 THEN in_row_reserved_page_count+lob_reserved_page_count+row_overflow_reserved_page_count ELSE 0 END))/CONVERT(numeric(19,3), 128)) AS SizeMB,

    CONVERT(numeric(19,3), CONVERT(numeric(19,3), SUM(CASE WHEN index_id>1 THEN in_row_reserved_page_count+lob_reserved_page_count+row_overflow_reserved_page_count ELSE 0 END))/CONVERT(numeric(19,3), 128)) AS SizeMBIndexes

    FROM sys.dm_db_partition_stats

    GROUP BY object_id

    ) AS partitions ON sys.objects.object_id=partitions.object_id

    WHERE sys.objects.type='u'

    ORDER BY sys.objects.name