数据库数据大小排名
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