declare @cursor_cv cursor,
@name varchar(50)
Create table #temp(name varchar(50),rows int,reserved varchar(50),data varchar(50),index_size varchar(50),unused varchar(50))
set @cursor_cv = cursor local
for select name
from sysobjects
where type = 'U'
for read only
open @cursor_cv
fetch next from @cursor_cv into @name
while (@@fetch_status = 0)
begin
insert into #temp
exec sp_spaceused @name
fetch next from @cursor_cv into @name
end
close @cursor_cv
deallocate @cursor_cv
select name 'name - 表名称',
ROWS 'rows - 记录行数(估计值)',
reserved 'reserved - 保留空间',
data 'data - 数据空间',
index_size 'index_size - 索引空间',
unused 'unused - 未使用空间'
from #temp order by rows DESC
drop table #temp
sql server 获取表空间,及资源占用情况declare @cursor_cv cursor, @name varchar(50) Create table #temp(name varchar(50),rows int,reserved varchar(50),data varchar(50),index_size varchar(50),unused varchar(50)) set @cursor_cv = cursor local for select name from