-- Dynamically builds T-SQL statements for retrieving the file
-- locations for all the databases in the SQL Server Instance
-- SQL Server versions supported: SQL Server 2005 or later
SELECT 'use '+ [name]+'; select '''+[name]+''' as DBName,cast ([name] as varchar(45)) as LogicalFileName,cast (filename as varchar(100)) as FileName from sysfiles;' as SQLStatement
Details: Just execute the statements generated from the above query and you will receive the file locations for all the databases in the SQL Server instance.
For more info, check out the following links:
Labels: SQL Server, SQL Server Administration, T-SQL Tips