'SQL Server - get all databases with MDF and LDF File Location
I need a T-SQL query for a list of all databases in SQL Server 2008 showing
- the name of the database and
- the location of the
.mdfand.ldffiles.
Solution 1:[1]
select
d.name as 'database',
mdf.physical_name as 'mdf_file',
ldf.physical_name as 'log_file'
from sys.databases d
inner join sys.master_files mdf on
d.database_id = mdf.database_id and mdf.[type] = 0
inner join sys.master_files ldf on
d.database_id = ldf.database_id and ldf.[type] = 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lava |

