开发者

tsql to get data files growth type in SQL 2000

I want开发者_JS百科 to know the growth type (% or MB) for database files on SQL server 2000. I Used sys.database_files files on Microsoft SQL Server 2005 to get this information. I tried using sysfiles on Microsoft SQL Server 2000 for this, but it wasn't good enough.


This query should help:

SELECT
  name,
  size,
  growth,
  status,
  size * 8 AS size_in_kb,
  size * 8 / 1024. AS size_in_mb,
  CASE WHEN status & 0x100000 > 0
       THEN growth 
       ELSE NULL END AS growth_in_percent,
  CASE WHEN status & 0x100000 = 0 
       THEN growth * 8 / 1024. END AS growth_in_mb  
FROM sysfiles


You can query the sysfiles system view:

SELECT * FROM sysfiles

It will give you quite a few bits for each file including its current size, its maximum size, and the growth (plus a flag whether that growth is a fixed number of pages, or a percentage).

See the MSDN documentation for the details on what the columns are and what they mean.


SELECT DB_NAME() AS DBName
,groupid AS FileGroup
,fileid AS FileID
,RTRIM(NAME) AS LogicalFileName
,filename AS PhysicalFileName
,CAST(size / 128.0 AS DECIMAL(10, 2)) AS Size_MB
,CAST(FILEPROPERTY(NAME, 'SpaceUsed') / 128.0 AS DECIMAL(10, 2)) AS SpaceUsed_MB
,CAST(size / 128.0 - (FILEPROPERTY(NAME, 'SpaceUsed') / 128.0) AS DECIMAL(10, 2)) AS AvailableSpace_MB
,CAST((CAST(FILEPROPERTY(NAME, 'SpaceUsed') / 128.0 AS DECIMAL(10, 2)) / CAST(size / 128.0 AS DECIMAL(10, 2))) * 100 AS DECIMAL(10, 2)) AS UsedPercentage
,CASE
    WHEN STATUS & 0x100000 > 0 THEN growth
    ELSE NULL
    END AS Growth_Percent
,CASE
    WHEN STATUS & 0x100000 = 0 THEN CAST(growth / 128.0 AS DECIMAL(10, 2))
    END AS Growth_MB
,CASE maxsize
    WHEN 0 THEN 'No growth is allowed'
    WHEN - 1 THEN 'File will grow until the disk is full'
    ELSE CONVERT(VARCHAR, CAST(maxsize / 128.0 AS DECIMAL(10, 2)))
    END AS MaxSize_MB 
FROM sysfiles

Just a bit more info

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜