番茄的梦想

那一抹夕阳

  博客园  :: 首页  ::  :: 联系 :: 订阅 订阅  :: 管理
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

  

posted on 2014-04-14 16:57  番茄的梦想  阅读(2193)  评论(0编辑  收藏  举报