Query to find Size Of each table in Database

Kirthiga
Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 1249
select o.name
, reservedpages = sum(a.total_pages)
, usedpages = sum(a.used_pages)
, pages = sum(case when a.type <> 1 then a.used_pages
when p.index_id < 2 then a.data_pages else 0 end)
, SUM(a.used_pages)*8096/1074000 AS 'Size(MB)'
, SUM(a.used_pages)*8096/1074000000 AS 'Size(GB)'
, rows = sum(case when (p.index_id < 2) and (a.type = 1) then p.rows else 0 end)
from sys.objects o
join sys.partitions p on p.object_id = o.object_id
join sys.allocation_units a on p.partition_id = a.container_id
where o.type = 'U'
group by o.name
order by 3 desc

Comments or Responses

Login to post response