码迷,mamicode.com
首页 > 数据库 > 详细

统计SqlServer数据库的表大小

时间:2021-05-24 09:55:32      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:des   object   dea   type   etc   order   stat   server   code   

create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_size varchar(100),unused varchar(100)) 
 
declare @name varchar(100) 
declare cur cursor  for 
    select name from sysobjects where xtype=u order by name 
open cur 
fetch next from cur into @name 
while @@fetch_status=0 
begin 
    insert into #data 
    exec sp_spaceused   @name      --取得表占用空间 
    print @name 
 
    fetch next from cur into @name 
end 
close cur 
deallocate cur 
 
create table #DataNew(name varchar(100),row int,reserved int,data int,index_size int,unused int) 
 
insert into #dataNew 
select name,convert(int,row) as rows,convert(int,replace(reserved,KB,‘‘)) as reserved,convert(int,replace(data,KB,‘‘)) as data, 
convert(int,replace(index_size,KB,‘‘)) as index_size,convert(int,replace(unused,KB,‘‘)) as unused from #data  
 
select name 表名,row 行数,reserved 占用空间KB,data 总大小KB,index_size 索引总大小KB,unused 空白页KB from #dataNew order by data desc
drop table #Data
drop table #DataNew

 

统计SqlServer数据库的表大小

标签:des   object   dea   type   etc   order   stat   server   code   

原文地址:https://www.cnblogs.com/kandyvip/p/14770498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!