Wednesday, 12 February 2014

How to get each table space and row counts in SQL server

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) 

No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...