Finding out database name using .mdf file

  • Hi,

    I've a SQL data file (.mdf) I would like to find out to which database it's linked to ?

    Is there a way to find out database name using .mdf file?

    Thanks

  • you could query sys.master_files and look for physical_name matching the .mdf you have.

    ------------------------------------------------------------------------
    Bite-sized fiction (with added teeth) [/url]

  • Hi,

    You can query sp_helpdb databasename for each DB on your SQL instance. This will list out the filenames (Primary, secondary) and the log file associated with the DB.

    PS.- Its difficult to find the DB just by looking at the .mdf filename, simply coz' people are at their free will to name files for a database. I have seen totally unrelated names given to files 🙂

    Thanks,

    Ninad

  • yep or check sys.database_files for the name and compare to your mdf.

  • thank you all 🙂

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

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