–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;
sqlserver 表大小查询
最新推荐文章于 2024-10-14 11:55:36 发布