laoq112

sqlserver 用于查看当前数据库所有表占用空间大小的存储过程

create procedure dbo.proc_getsize
as
begin
create table #temp
(
   t_id int primary key identity(1,1),
   t_name sysname,                        --表名
   t_rows int,                            --总行数
   t_reserved varchar(50),                --保留的空间总量
   t_data varchar(50),                    --数据总量
   t_indexsize varchar(50),               --索引总量
   t_unused varchar(50)                   --未使用的空间总量
)

exec SP_MSFOREACHTABLE N\'insert into #temp(t_name,t_rows,t_reserved,t_data,t_indexsize,t_unused) exec SP_SPACEUSED \'\'?\'\'\'

select t_id,t_name,t_rows,t_reserved,t_indexsize,t_unused,t_data,
    case when cast(replace(t_data,\' KB\',\'\') as float)>1000000 then cast(cast(replace(t_data,\' KB\',\'\') as float)/1000000 as varchar)+\' GB\' 
        when cast(replace(t_data,\' KB\',\'\') as float)>1000 then cast(cast(replace(t_data,\' KB\',\'\') as float)/1000 as varchar)+\' MB\' 
    else t_data end as datasize
from #temp 
order by cast(replace(t_data,\' KB\',\'\') as float) desc

drop table #temp
end

 

分类:

技术点:

相关文章:

  • 2021-12-22
  • 2021-12-23
  • 2021-07-11
  • 2021-09-19
  • 2021-12-13
  • 2021-06-12
  • 2021-11-19
猜你喜欢
  • 2021-12-08
  • 2021-08-14
  • 2021-11-19
  • 2021-08-31
  • 2021-06-15
  • 2022-02-07
  • 2021-12-31
相关资源
相似解决方案