SQL Server统计数据库中每张表的行数、大小、索引空间
1、统计数据库中每张表的大小
首先执行下面的命令
1 | exec sp_MSforeachtable @command1= "sp_spaceused '?'" ; |
检测当前数据库版本是否支持存储过程“sp_MSforeachtable”,
如果执行成功则可以使用下面的命令
06 | index_size varchar (50), |
11 | name , rows , reserved, data, index_size, unused |
12 | ) exec sp_MSforeachtable @command1= "sp_spaceused '?'" ; |
14 | select * from tmp where name <> 'tmp' order by data desc ; |
-
rows:行数
-
reserved:数据库为该表分配的空间
-
data:数据实际使用的空间,reserved肯定>=data
-
index_size:索引使用的空间
-
unused:为数据库中的对象保留但尚未使用的空间总量,
-
大致等于reserved - data - index_size的值
2、统计数据库中每张表的行数
1 | SELECT DISTINCT a. name , |
6 | AND a.type = 'u' AND b. rows >0 |
原文链接:SQL Server统计数据库中每张表的行数、大小、索引空间