Check .mdf and .ldf file size using T-SQL

  • Hello,

    Please tell me a query which i can use to get a result like below table

    Database_NameDataType Size in MB

    DB1 Data 2550

    DB1 Log 1345

    please remember I'm asking about .mdf and .ldf file size not .bak and .trn.

    I tried DBCC sqlperf(logspace) - that gives me the correcct .ldf file size but doesn't provide .mdf file size.

    I also tried Sp_helpdb - but that doesn't categories between .mdf and .ldf. It just gives the DB size, which is not what i want.

    Please suggest.

    Rgds,
    Pankaj

  • Try this.

    sp_helpdb 'database Name'

    -Vikas Bindra

  • Thanks Vikas,

    Rgds,
    Pankaj

  • You can also query sys.database_files (must be run in the context of the database you are interested in). You do need to convert the size from 8kb pages to MB. Here's a query that does it:

    SELECT

    [file_id],

    [type],

    type_desc,

    data_space_id,

    [name],

    physical_name,

    state,

    state_desc,

    size,

    size * 8 / 1024.00 AS size_in_mb

    FROM

    sys.database_files AS DF

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply