sp_spaceused [<objname >[,1] ]
<objname>
是表的名称,就是要报告该表的情况。如果省略,将显示当前数据库中使用的空间的摘要。
1
分别输出有关表的索引和 text/image 存储的信息。
报告为 titles 表分配(保留)的空间量、用于数据的空间量、用于索引的空间量和可用(未使用的)空间量:
sp_spaceused titles
name rowtotal reserved data index_size unused
---------- --------- --------- ------- ---------- ----------
titles 18 46 KB 6 KB 4 KB 36 KB
除有关 titles 表的信息外,还输出该表上各个索引的信息:
sp_spaceused titles, 1
index_name size reserved unused
-------------------- ---------- ---------- ----------
titleidind 2 KB 32 KB 24 KB
titleind 2 KB 16 KB 14 KB
name rowtotal reserved data index_size unused
---------- -------- --------- ------- ---------- ----------
titles 18 46 KB 6 KB 4 KB 36 KB
分别显示 text/image 页存储使用的空间和该表使用的空间。text/image 存储的对象名称为“t”加上表的名称:
sp_spaceused blurbs,1
index_name size reserved unused
-------------------- ---------- ---------- ----------
blurbs 0 KB 14 KB 12 KB
tblurbs 14 KB 16 KB 2 KB
name rowtotal reserved data index_size unused
---------- -------- ----------- ------- ---------- ----------
blurbs 6 30 KB 2 KB 14 KB 14 KB
输出当前数据库中使用的空间的摘要:
sp_spaceused
database_name database_size
--------------- ---------------------------
master 5 MB
reserved data index_size unused
--------- --------- ----------- --------
2176 KB 1374 KB 72 KB 730 KB
报告为事务日志保留的空间量和可供事务日志使用的空间量:
sp_spaceused syslogs
name rowtotal reserved data index_size unused
---------- --------- --------- ------- ---------- ----------
syslogs Not avail. 32 KB 32 KB 0 KB 0 KB
使用 sp_spaceused 时,还存在一些其它注意事项:
update statistics、dbcc checktable 和 dbcc checkdb 命令更新每页行数的估计值,因此在运行这些命令中的一个之后,rowtotal 最准确。如果需要精确的行数,应使用 select count(*)。