Quantcast
Channel: T-SQL – SQL Steve
Viewing all articles
Browse latest Browse all 13

SQL Server 2008 Data File Size

$
0
0
Sql Server Consultant

Sql Server Consultant – Steve Abraham

SQL Server Consultant ~ Steve Abraham provides tips for capturing size and state of data files for SQL Server databases.

If you are looking to capture the size and state of all data files for all of your SQL Server databases on a given instance, the script below should do the trick.

usemaster
GO
SELECT
    d.name                                  AS DatabaseName,
    mf.type_desc                            AS FileType,
    mf.name                                 ASFileName,
    mf.physical_name                        AS DatafilePhysicalName,
    mf.state_desc                           AS DatafileState,
    CONVERT(NVARCHAR(25), mf.size / 128)    AS DatafileCurrentSize,
    CASE mf.max_size
        WHEN1 THEN‘Unlimited’
        ELSECONVERT(NVARCHAR(25), mf.max_size / 128)+‘ MB’
    END                                     AS DatafileMaxSize,
    CASE mf.is_percent_growth
        WHEN 1 THENCONVERT(NVARCHAR(3), mf.growth)+‘ Percent’
        ELSECONVERT(NVARCHAR(25), mf.growth / 128)+‘ MB’
    END                                     AS DatafileGrowth,
    mf.is_media_read_only                   AS IsMediaReadOnly,
    mf.is_read_only                         AS IsFileReadOnly,
    mf.is_sparse                            AS IsFileSparse
FROM
    sys.master_filesAS mf
    INNERJOIN
    sys.databasesAS d
    ON
    mf.database_id = d.database_id
ORDERBY
    DatabaseName,
    FileType DESC,
    FileName
GO

Please feel free to ping me with any questions or requests.  Smile


Filed under: SQL Server 2008, T-SQL Tagged: Data File, database inventory, Size, sys.master_files

Viewing all articles
Browse latest Browse all 13

Latest Images

Trending Articles





Latest Images