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';




For user  databases :


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

Popular posts from this blog

Interview Questions on AOAG

Database Administrator Designations

Interview questions for Junior SQL server DBA.