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 id drop table ##'
@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 id drop table ##'
本文介绍如何使用SQL脚本`execsp_MSForEachTable`创建包含表信息的临时表,并通过`insert`和`update`操作填充数据,最终使用`select`查询结果并删除临时表。

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



