SQL

SELECT TOP 10
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,

SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.total_pages) * 8 / 1000 AS TotalSpaceMB,
SUM(a.total_pages) * 8 / 1000000 AS TotalSpaceGB,

SUM(a.used_pages) * 8 AS UsedSpaceKB,
SUM(a.used_pages) * 8 / 1000 AS UsedSpaceMB,
SUM(a.used_pages) * 8 / 1000000 AS UsedSpaceGB,

(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1000 AS UnusedSpaceMB

FROM
sys.tables t

INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id

INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id

INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id

LEFT OUTER JOIN
sys.schemas s ON t.schema_id = s.schema_id

WHERE
t.NAME NOT LIKE 'dt%'
AND 
t.is_ms_shipped = 0

AND 
i.OBJECT_ID > 255

GROUP BY
t.Name, s.Name, p.Rows

ORDER BY
TotalSpaceKB desc

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值