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

SQL Server 查看数据表占用空间大小的SQL语句

时间:2015-01-23 11:02:30      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:

 1 declare @name varchar(1000)
 2 declare @sql varchar(1000)
 3 
 4 if object_id(tempdb..#space) is not null drop table #space
 5 create table #space(name varchar(50),rows bigint,reserved varchar(12),data varchar(12),index_size varchar(12),unused varchar(12))
 6 
 7 declare sp cursor local for select [+name+] from sysobjects where type = u
 8 open sp
 9 fetch sp into @name
10 while @@fetch_status = 0
11 begin
12 set @sql = insert into #space exec sp_spaceused  + @name
13 exec(@sql)
14 fetch sp into @name
15 end
16 close sp
17 
18 select * from #space order by cast(replace(reserved,kb,‘‘)as int) desc

来自:SQL Server技术产品群(250942633)群友

本人独立博客:http://www.haoyuncn.net/sql-server-space

SQL Server 查看数据表占用空间大小的SQL语句

标签:

原文地址:http://www.cnblogs.com/cyun/p/4243372.html

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