G - M
G - M

Reputation:

Query in MSSQL that returns .mdf and .ldf filename/location for specific database?

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

Upvotes: 9

Views: 20775

Answers (3)

GvS
GvS

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

Roger Lipscombe
Roger Lipscombe

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

gbn
gbn

Reputation: 432662

SELECT * FROM sys.database_files (SQL 2005+)

SELECT * FROM dbo.sysfiles (SQL 2000)

Upvotes: 17

Related Questions