How to Get MDF and LDF Physical File names out of SQL

  • I was wondering if anyone knows how to pull just the mdf and ldf physical file name from SQL. I know you can pull the entire directory by querying the system tables but I cannot figure out if their is a way to pull just the file name.

  • Try this...

    Select

    SUBSTRING(physical_name,LEN(physical_name)- CHARINDEX('\',REVERSE(physical_name))+2 ,LEN(physical_name))

    FROM sys.master_files

  • Or this would work:

    select

    reverse(left(reverse(physical_name), charindex('\', reverse(physical_name)) - 1)),

    *

    from

    sys.master_files

  • Perfect!!!

    Thanks Ken

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

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