--查所有表的记录数,保留空间,使用空间,索引使用空间,未用空间set nocount on
exec sp_MSForEachTable
@precommand=N'
create table ##(
id int identity,
表名 sysname,
字段数 int,
记录数 int,
保留空间 Nvarchar(10),
使用空间 varchar(10),
索引使用空间 varchar(10),
未用空间 varchar(10))',
@command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''
update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()',
@postcommand=N'select * from ## order by 记录数 desc drop table ##'
set nocount off

本文提供了一段SQL Server脚本,用于查询所有表的记录数、字段数量,并统计每个表的保留空间、使用空间、索引使用空间及未用空间。通过此脚本可以有效地管理和监控SQL Server中各表的空间使用情况。

被折叠的 条评论
为什么被折叠?



