Reputation:
Can I use a query in MSSQL to get the .mdf and .ldf filename/location for a specific database?
Upvotes: 9
Views: 20775
Reputation: 52503
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.
Upvotes: 6
Reputation: 91965
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.
Upvotes: 4
Reputation: 432662
SELECT * FROM sys.database_files (SQL 2005+)
SELECT * FROM dbo.sysfiles (SQL 2000)
Upvotes: 17