sqlserver 表大小查询

–Sqlserver 查询数据库 大小
SELECT * FROM
(
SELECT
DB_NAME(database_id) AS DatabaseName,
type_desc AS FileType,
name AS FileName,
size * 8 / 1024/1024 AS FileSizeGB
FROM sys.master_files
WHERE type = 0 – 数据文件
AND state = 0 – 在线状态
) T1 ORDER BY FileSizeGB DESC
1
2
3
4
5
6
7
8
9
10
11
SqlServer 查询数据表 大小
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
CONVERT(decimal(18,2), SUM(a.total_pages) * 8.0 / 1024 / 1024) AS TotalSpaceGB,
CONVERT(decimal(18,2), SUM(a.used_pages) * 8.0 / 1024 / 1024) AS UsedSpaceGB,
CONVERT(decimal(18,2), (SUM(a.total_pages) - SUM(a.used_pages)) * 8.0 / 1024 / 1024) AS UnusedSpaceGB
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
GROUP BY
t.NAME, s.Name, p.Rows
ORDER BY
TotalSpaceGB DESC;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值