SQL查看表数据占用空间代码

 1 create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_size varchar(100),unused varchar(100))
 2  
 3 declare @name varchar(100)
 4 declare cur cursor  for
 5     select name from sysobjects where xtype=’u’ order by name
 6 open cur
 7 fetch next from cur into @name
 8 while @@fetch_status=0
 9 begin
10     insert into #data
11     exec sp_spaceused   @name
12     print @name
13  
14     fetch next from cur into @name
15 end
16 close cur
17 deallocate cur
18  
19 create table #DataNew(name varchar(100),row int,reserved int,data int,index_size int,unused int)
20  
21 insert into #dataNew
22 select name,convert(int,row) as row,convert(int,replace(reserved,’KB’,’’)) as reserved,convert(int,replace(data,’KB’,’’)) as data,
23 convert(int,replace(index_size,’KB’,’’)) as index_size,convert(int,replace(unused,’KB’,’’)) as unused from #data 

 

posted @ 2019-05-30 16:14  温故余学  阅读(390)  评论(0编辑  收藏  举报