自来云

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
--查询表空间大小
declare @name varchar(1000)
declare @sql varchar(1000)
if object_id('tempdb..#space') is not null drop table #space 
create table #space(name varchar(50),rows bigint,reserved varchar(12),data varchar(12),index_size varchar(12),unused varchar(12))
declare sp cursor local for select '['+name+']' from sysobjects where type = 'u'
open sp
fetch sp into @name
while @@fetch_status = 0
begin
set @sql = 'insert into #space exec sp_spaceused ' + @name
exec(@sql)
fetch sp into @name
end
close sp
select * from #space order by cast(replace(reserved,'kb','')as int) desc

 

posted on 2018-05-27 17:17  自来云  阅读(177)  评论(0编辑  收藏  举报