Technical Article

List table space usage and row counts

,

Run this query in database you would like to see listed the space used and row counts of all tables.

SELECT 

    SCHEMA_NAME(o.schema_id) + ',' + OBJECT_NAME(p.object_id) AS name,

    reserved_page_count * 8 as space_used_kb,

    row_count

FROM 

    sys.dm_db_partition_stats AS p

        JOIN sys.all_objects AS o ON p.object_id = o.object_id

WHERE

    o.is_ms_shipped = 0

ORDER BY

    SCHEMA_NAME(o.schema_id) + ',' + OBJECT_NAME(p.object_id)

Read 16 times
(2 in last 30 days)

Rate

3.25 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

3.25 (4)

You rated this post out of 5. Change rating