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
4 comments:
Hi,
Your blog has helped me a lot - thank you for sharing. I was hoping you could help me find the location of the sql logfiles in a similar method. I know this information is stored in the registry, but I do not want to look it up in the registry, I am rather looking for a SQL query, that will retrieve the current location where the log files are being written to. I hope you could help please?
Hello,
Thank you for sharing your blog, it is very helpfull. I would like to ask your help in finding the location of the sql log files. I am assuming that it would be similar to what you've done to get the MDF and LDF files, but so far I had no luck in retrieving it. I do not want to do a lookup into the registry to find it, and would prefer to use a sql query.
Could you please help?
Thank you so much!!!!!!
You help me A LOT!!!!
Harriet,
I am bit confused with your comments. Are you searching for the file details in registry. I think, it will be stored as a physical content. Can you eloborate your question please.
Thanks and Regards,
Venkatesan Prabu .J
Post a Comment