程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 數據庫大小分布情況

數據庫大小分布情況

編輯:關於SqlServer

---數據庫大小分布情況

SET NoCount ON

CREATE TABLE #DBsize

   (

     [DatabaseName] [nvarchar](75) NOT NULL ,

     [Size] [decimal] NOT NULL ,

     [Name] [nvarchar](75) NOT NULL ,

     [Filename] [nvarchar](300) NOT NULL

   )

CREATE TABLE #drives

   (

     [Drive] [char](5) NOT NULL ,

     [MBFree] [decimal] NOT NULL

   )

INSERT  INTO #DBsize

       EXEC sp_MSforeachdb 'Select ''? '' as DatabaseName, Case When [?]..sysfiles.size * 8 / 1024 = 0 Then 1 Else [?]..sysfiles.size * 8 / 1024 End

AS size,[?]..sysfiles.name,

[?]..sysfiles.filename From [?]..sysfiles'

INSERT  INTO #drives

       EXEC xp_fixeddrives

SELECT  @@Servername AS 服務器名 ,

       COUNT(DISTINCT RTRIM(CAST(DatabaseName AS VARCHAR(75)))) AS 數據庫數目 ,

       Drive AS [使用的總數據空間] ,

       CAST(SUM (Size) AS VARCHAR(10)) AS [總大小(MB)] ,

       CAST(MBFree AS VARCHAR(10)) AS [剩余大小(MB)]

FROM    #DBsize

       INNER JOIN #drives ON LEFT(#DBsize.Filename, 1) = #drives.Drive

GROUP BY Drive ,

       MBFree

 

SELECT  RTRIM(CAST(DatabaseName AS VARCHAR(75))) AS [數據庫名] ,

       Drive AS [盤符] ,

       Filename AS [文件名] ,

       CAST(Size AS INT) AS [大小(MB)] ,

       CAST(MBFree AS VARCHAR(10)) AS [剩余大小 (MB)]

FROM    #DBsize

       INNER JOIN #drives ON LEFT(#DBsize.Filename, 1) = #drives.Drive

GROUP BY DatabaseName ,

       Drive ,

       MBFree ,

       Filename ,

       CAST(Size AS INT)

ORDER BY [盤符] ,

       [剩余大小(MB)] DESC

DROP TABLE #DBsize

DROP TABLE #drives

查看本欄目

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved