SQL скрипт подсчета места в базе
Скрипт для подсчета места в MS SQL 2008 ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
select a2.name [Table], replace(convert (nvarchar, convert(money, a1.rows), 1), '.00','') [Row Count], cast (a1.reserved/128.0/1024 as decimal(9,3)) [Reserved GB], case when a1.reserved = 0 then 0 else cast ((100-(100.0*a1.used/a1.reserved)) as decimal(9,2)) end [Unused %] from ( select ps.object_id, sum (cast (ps.row_count as bigint)) rows, sum (cast (ps.reserved_page_count as bigint)) reserved, sum (cast (ps.used_page_count as bigint)) used from sys.dm_db_partition_stats ps inner join sys.all_objects a2 on a2.object_id = ps.object_id and a2.type IN ('U') group by ps.object_id ) a1 left join sys.all_objects a2 ON a1.object_id = a2.object_id where (a1.reserved/128) > 5 ORDER BY a1.rows DESC, a2.name |
Вывод выглядит так: