Skip to content

Instantly share code, notes, and snippets.

@yorek
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorek/a7db2e295e6542dea5cd to your computer and use it in GitHub Desktop.
Save yorek/a7db2e295e6542dea5cd to your computer and use it in GitHub Desktop.
Return table (split by index and partition) size and row count
DECLARE @tableNamePattern SYSNAME = '%'
SELECT
t.name,
p.index_id,
p.partition_number,
[rows] = format(p.row_count, '#,0'),
used_space = format(p.used_page_count * 8 / 1024., '#,0 MB'),
reserved_space = format(p.reserved_page_count * 8 / 1024., '#,0 MB')
FROM
sys.dm_db_partition_stats p
INNER JOIN
sys.tables t ON t.object_id = p.object_id
WHERE
t.name LIKE @tableNamePattern
ORDER BY
t.name, p.index_id, p.partition_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment