指令碼:
create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),
index_size varchar(100),unused varchar(100)); create table #DataNew(name varchar(100),row int,reserved int,data int,index_size int,unused int)
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
fetch next from cur into @name
end
close cur
deallocate cur
insert into #dataNew select name,convert(int,row) as row,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 * from #dataNew order by data desc;
drop table #Data;
drop table #DataNew;
結果列說明:
name:表名
row : 表中資料的總行數
reserved:為表保留的空間總量
data:表中的資料所使用的空間總量
index_size:表中的索引所使用的空間總量
unused:為表保留但尚未使用的空間總量