mssql sqlserver 快速获取所有表对象所占用空间的大小


摘要:
处于对数据库的例行检查,我们需要监控数据库有每一张表所占用的空间大小,
下文将分享通过sql脚本,获取数据库中表对象所占用的空间大小,如下所示:

 SELECT b.name, SUM(a.reserved_page_count) AS [数据页数], SUM(a.used_page_count) AS [已用数据页数]
	, SUM(CASE 
		WHEN a.index_id < 2 THEN a.in_row_data_page_count + a.lob_used_page_count + a.row_overflow_used_page_count
		ELSE a.lob_used_page_count + a.row_overflow_used_page_count
	END) AS [数据页], SUM(CASE 
		WHEN a.index_id < 2 THEN row_count
		ELSE 0
	END) AS [表行数]
FROM sys.dm_db_partition_stats a
	INNER JOIN sys.objects b ON a.object_id = b.object_id
GROUP BY b.name
mssql_sqlserver_数据空间占用大小分析

mssql_sqlserver_数据空间占用大小分析