Tuesday, January 06, 2015

Get Names & Locations of Data and Log Files

Every now and then I want the file names for when I am restoring a database from a different server. Plug in your DB name and this gives where the data files and logs are and what they are called.

USE Master
GO

SELECT
CONCAT('move','''',space(1),name,'''',space(1),'TO','''',SPACE(1),Physical_name,'''',',')
FROM sys.master_files

WHERE db_name(database_id) = 'DB_Name_Here'

0 Comments:

Post a Comment

<< Home