现在的位置: 首页 > 综合 > 正文

查询表的使用空间和可用空间

2012年08月26日 ⁄ 综合 ⁄ 共 627字 ⁄ 字号 评论关闭

  查询表的使用空间和可用空间

set nocount on
exec sp_MSForEachTable
@precommand=N'
create table ##(
id int identity,
表名 sysname,
字段数 int,
记录数 int,
保留空间 varchar(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 表名,记录数,replace(保留空间,''KB'','''')/1024 已经分配空间MB,replace(使用空间,''KB'','''')/1024 数据使用空间MB
,replace(索引使用空间,
''KB'','''')/1024 索引使用空间MB,replace(未用空间,''KB'','''')/1024 未用空间MB from ## order by 记录数 desc drop table ##'
set nocount off

抱歉!评论已关闭.