find out all mdf and ldf files being used by the sql instance

jamesmetcalf74 used Ask the Experts™
I have an instance of sql that has a fair amount of databases.  not all of the mdf files match the name of the associated db's perfectly.  Is there a quick way i can make a list of all the mdf files and ldf files that are currently "attached" to the instance?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Engineer
Distinguished Expert 2017
Try this:
exec sp_msforeachdb 'USE ?; SELECT DB_NAME(), name, filename FROM sys.sysfiles'

Open in new window

Brian CroweDatabase Administrator
Top Expert 2005
SELECT * FROM sys.master_files

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial