A simple way to get the default SQL Server data and log path (finally!)

Prior to SQL Server 2012 extracting the default and data path was not straightforward, but now, there is a simple way to get this information via a query.

For things like automated SQL Server build scripts (and probably many other reasons) finding the root data and log file paths is essential. Prior to SQL Server 2012 there were all sorts of options ranging from e.g. running sp_helpfile against the master database (which is not foolproof) or constructing a string to establish the right […]