views:

23

answers:

3

Hi Folks,

How do I get the Physical Database and Log File location (file system path) of a DB in SQL Server 2005?

I used this to get the mdf file: {SELECT [Name], FileName FROM sysdatabases} but need to get the log file as well...

Cheers, Conor

+1  A: 

SELECT * FROM sys.database_files

Will A
Doesnt show where the log file is when I run this, only the filename path of the mdf file?
Conor
Opps you are correct I was querying the sysdatabases, sorry!!Thanks
Conor
Interesting - this includes log files for me, and the docs (http://msdn.microsoft.com/en-us/library/ms174397.aspx) don't imply otherwise.
Will A
No problem - enjoy the system views!
Will A
+1  A: 

Here is another way

select * from sys.sysaltfiles
SQLMenace
cool thanks very much!!
Conor
+1 - but watch out for this disappearing in a future version, sys.master_files is the recommended alternative to this view.
Will A
+2  A: 

You should be using sp_helpdb or sp_helpfile for this.

e.g:

sp_helpdb 'master'
JimG
Why? Admittedly this provides some additional, potentially useful, information - but there's nothing wrong with querying the system views.
Will A
sp_helpdb reports wrong info against a snapshot, see here http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/running-sp_helpdb-against-a-snapshot-sho-2008
SQLMenace
Nothing wrong, until they move stuff around... recently saw a problem where a query broke due to differences in 2000 and 2005. Using the procedures would have avoided that problem. Interesting about the snapshot breakage though.
JimG