Get Table and Index storage size in sql server -
i want table data , index space every table in database:
table name data space index space -------------------------------------------------------
how can achieve result?
this query here list total size table takes - clustered index, heap , nonclustered indices:
select s.name schemaname, t.name tablename, p.rows rowcounts, sum(a.total_pages) * 8 totalspacekb, sum(a.used_pages) * 8 usedspacekb, (sum(a.total_pages) - sum(a.used_pages)) * 8 unusedspacekb sys.tables t inner join sys.schemas s on s.schema_id = t.schema_id inner join sys.indexes on t.object_id = i.object_id inner join sys.partitions p on i.object_id = p.object_id , i.index_id = p.index_id inner join sys.allocation_units on p.partition_id = a.container_id t.name not 'dt%' -- filter out system tables diagramming , t.is_ms_shipped = 0 , i.object_id > 255 group t.name, s.name, p.rows order s.name, t.name
if want separate table space index space, need use and i.index_id in (0,1)
table space (index_id = 0
heap space, index_id = 1
size of clustered index = data pages) , and i.index_id > 1
index-only space
Comments
Post a Comment