Is it possible to retrieve the physical location of my data file and log file?
I am struck up with retrieving details for data and log file location of our existing databases and found that the key table is located in the master databases. Below is the query to retrieve that information,
select * from [master].[sys].[master_files]
On executing the query above, we will get the below result set,
DECLARE @sql_path NVARCHAR(256) ;
SELECT @sql_path = SUBSTRING([physical_name], 1, CHARINDEX(N'master.mdf', LOWER([physical_name])) - 1)
FROM [master].[sys].[master_files]
WHERE [database_id] = 1
AND [file_id] = 1 ;
print @sql_path
