数据库数据大小排名

DECLARE @dbtName NVARCHAR(50)

CREATE TABLE #result_HJUHYFGTR48sjsjasdldshfjkshdasad

( 

     NAME      NCHAR(256) ,

     SIZE      INT

)

DECLARE pcurr CURSOR 

FOR

    SELECT NAME

    FROM   sys.databases

 

 

OPEN pcurr  

FETCH NEXT FROM pcurr INTO @dbtName  

WHILE (@@fetch_status = 0)

BEGIN

    DECLARE @sql VARCHAR(8000)

    SET @sql = 'SELECT    name,size  FROM ' + @dbtName + '.dbo.sysfiles where fileid=1  '

   

    INSERT INTO #result_HJUHYFGTR48sjsjasdldshfjkshdasad

    EXEC (@sql)

   

    FETCH NEXT FROM pcurr INTO @dbtName

END  

CLOSE pcurr  

DEALLOCATE pcurr  

 

SELECT *FROM   #result_HJUHYFGTR48sjsjasdldshfjkshdasad order by  size desc

drop table #result_HJUHYFGTR48sjsjasdldshfjkshdasad

posted @ 2011-09-15 11:35  qanholas  阅读(462)  评论(0编辑  收藏  举报