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

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

相关文章:

  • 2021-06-06
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-07-15
  • 2021-12-19
  • 2021-12-15
猜你喜欢
  • 2022-03-01
  • 2021-07-26
  • 2021-09-12
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案