Is it possible to list information about the files (MDF/LDF) of all databases on an SQL Server?
I\'d like to get a list showing which database is using what files on th
The query will error if multiple data files (e.g. ".ndf" file types) are used in one of the databases.
Here's a version of your query using joins instead of the sub-queries.
Cheers!
SELECT
db.name AS DBName,
db.database_id,
mfr.physical_name AS DataFile,
mfl.physical_name AS LogFile
FROM sys.databases db
JOIN sys.master_files mfr ON db.database_id=mfr.database_id AND mfr.type_desc='ROWS'
JOIN sys.master_files mfl ON db.database_id=mfl.database_id AND mfl.type_desc='LOG'
ORDER BY db.database_id