Pages

Social Icons

Monday 10 February 2014

Physical Path of Database in SQL

Hi All,

Below are the two queries which help us to find the full path of the data folder in SQL.

This query Return Full physical path till Data Folder in SQL
                                                         
SELECT SUBSTRING(FILENAME, 1, CHARINDEX(N'<database_name>', LOWER(FILENAME)) - 1)
FROM master.dbo.sysdatabases WHERE name = '<database_name>'

This query Return Full physical path till Data Folder in SQL for all the database present in sql

SELECT
   mf.name
  ,mf.physical_name
  ,reverse(left(reverse(physical_name), charindex('\', reverse(physical_name)) -1))

 FROM sys.master_files mf 

Thanks,
RS

No comments:

Post a Comment