本文主要是介绍SqlServer 查询数据库 和 数据表 大小的语句,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
–Sqlserver 查询数据库 大小
SELECT * FROM
(SELECT DB_NAME(database_id) AS DatabaseName,type_desc AS FileType,name AS FileName,size * 8 / 1024/1024 AS FileSizeGBFROM sys.master_filesWHERE type = 0 -- 数据文件AND state = 0 -- 在线状态
) T1 ORDER BY FileSizeGB DESC
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 查询数据库 和 数据表 大小的语句的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!