sqlserver查看表空间

database

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

createprocedure dbo.proc_getsize

as

begin

createtable #temp

(

t_id intprimarykeyidentity(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,

casewhencast(replace(t_data," KB","") asfloat)>1000000thencast(cast(replace(t_data," KB","") asfloat)/1000000asvarchar)+" GB"

whencast(replace(t_data," KB","") asfloat)>1000thencast(cast(replace(t_data," KB","") asfloat)/1000asvarchar)+" MB"

else t_data endas datasize

from #temp

orderbycast(replace(t_data," KB","") asfloat) desc

droptable #temp

end

 

以上是 sqlserver查看表空间 的全部内容, 来源链接: utcz.com/z/531448.html

回到顶部