Take the 2-minute tour ×

Can I use a query in MSSQL to get the .mdf and .ldf filename/location for a specific database?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

SELECT * FROM sys.database_files (SQL 2005+)

SELECT * FROM dbo.sysfiles (SQL 2000)

share|improve this answer
add comment

You can use:

exec sp_helpfile

Will return a query containing information about the files of the current database.

This will work on any SQL server version.

share|improve this answer
add comment
SELECT * FROM sys.master_files

...will give you a basic view of where your database lives. It might not cope too well with filegroups, etc.

share|improve this answer
add comment

Your Answer

