Scripts to find the path of single database and multiple user databases
Script to get path of MDF and LDF for
a database:
SELECT
name AS [Database Name],
physical_name AS [MDF File Path],
(SELECT physical_name FROM
sys.master_files WHERE database_id = DB_ID() AND type_desc = 'LOG') AS [LOG
File Path]
FROM
sys.master_files
WHERE
database_id = DB_ID() AND type_desc = 'ROWS';
SELECT
DB_NAME(database_id) AS [Database Name],
physical_name AS [MDF File Path],
(SELECT physical_name FROM
sys.master_files WHERE database_id = DB_ID() AND type_desc = 'LOG') AS [LOG
File Path]
FROM
sys.master_files
WHERE
database_id > 4 AND type_desc = 'ROWS';
Comments
Post a Comment