Chinaunix首页 | 论坛 | 博客
  • 博客访问: 716473
  • 博文数量: 127
  • 博客积分: 2032
  • 博客等级: 大尉
  • 技术积分: 1446
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-04 10:20
文章分类

全部博文(127)

分类: Mysql/postgreSQL

2012-06-05 07:43:46

一, SQL2000

     SELECT  OBJECT_NAME(id) tablename ,
        8 * reserved / 1024 reserved ,
        RTRIM(8 * dpages / 1024) + 'Mb' used ,
        8 * ( reserved - dpages ) / 1024 unused ,
        8 * dpages / 1024 - rows / 1024 * minlen / 1024 free ,
        rows ,
        *
FROM    sysindexes
--where indid=1
ORDER BY reserved DESC

二,SQL2005

   DECLARE @tablespaceinfo TABLE (  
    nameinfo varchar(50),  
    rowsinfo int,  
    reserved varchar(20),  
    datainfo varchar(20),  
    index_size varchar(20),  
    unused varchar(20)  
)  
 
DECLARE @tablename varchar(255);  
 
DECLARE Info_cursor CURSOR FOR 
    SELECT [name] FROM sys.tables WHERE type='U';  
 
OPEN Info_cursor  
FETCH NEXT FROM Info_cursor INTO @tablename  
 
WHILE @@FETCH_STATUS = 0  
BEGIN 
    insert into @tablespaceinfo exec sp_spaceused @tablename  
    FETCH NEXT FROM Info_cursor  
    INTO @tablename  
END 
 
CLOSE Info_cursor  
DEALLOCATE Info_cursor  
 
SELECT * FROM @tablespaceinfo  
    ORDER BY Cast(Replace(reserved,'KB','') as INT) DESC 
阅读(4611) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~