Link to home
Start Free TrialLog in
Avatar of CAMSYSTEMS
CAMSYSTEMSFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Server 2005 Database File Path (mdf ldf files)

Is there a way from an SQL Server 2005 query to find out the path of the Database Files (mdf and ldf files).

I can get this information from right clicking on the database, going to properties and then to Files but I need to get this information using a query to use as part of a backup query.

Any ideas
Avatar of Aneesh
Aneesh
Flag of Canada image

sp_HelpDB 'dBName'  or
sp_HelpFile 'dbNAME'
ASKER CERTIFIED SOLUTION
Avatar of Sham Haque
Sham Haque
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CAMSYSTEMS

ASKER

Is there anyway of getting just the path (without the filename) or do I have to get a substring of the physical_name?
you need to use substring for this
use adventureworks
go
select substring(physical_name,1,charindex([name],physical_name)-1)
from sys.database_files
if you need it without the last backslash [\], change -1 to -2
:-)