set nocount on exec sp_MSForEachTable @precommand=N' create table ##( id int identity, 表名 sysname, 字段数 int, 记录数 int, 保留空间 Nvarchar(20), 使用空间 varchar(20), 索引使用空间 varchar(20), 未用空间 varchar(20))', @command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?'' update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()', @postcommand=N'select id, 表名, 字段数 列数, (记录数/10000.0) 记录数万, (Convert(bigint,rtrim(Replace(保留空间,''KB'','''')))/1024.0) 保留空间M, (Convert(bigint,rtrim(Replace(使用空间,''KB'','''')))/1024.0) 使用空间M, (Convert(bigint,rtrim(Replace(索引使用空间,''KB'','''')))/1024.0) 索引使用空间M, (Convert(bigint,rtrim(Replace(未用空间,''KB'','''')))/1024.0) 未用空间M from ## a order by 使用空间M desc; drop table ##' set nocount off