Skip to content

Instantly share code, notes, and snippets.

@chrisg32
Created February 5, 2018 20:19
Show Gist options
  • Save chrisg32/58ec7e45375e5a7e02365ccf58cf4f70 to your computer and use it in GitHub Desktop.
Save chrisg32/58ec7e45375e5a7e02365ccf58cf4f70 to your computer and use it in GitHub Desktop.
Lists the SQL Server databases and their corresponding file locations.
SELECT db.[name], mdf.[physical_name] AS [Data File], ldf.[physical_name] AS [Log File]
FROM [master].[sys].[databases] db
INNER JOIN [master].[sys].[master_files] mdf ON db.[database_id] = mdf.[database_id] AND mdf.[type] = 0
INNER JOIN [master].[sys].[master_files] ldf ON db.[database_id] = ldf.[database_id] AND ldf.[type] = 1
--WHERE lower(mdf.[physical_name]) LIKE 'c%' OR lower(ldf.[physical_name]) LIKE 'c%'
ORDER BY db.[name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment