Suppose you want to find out the path where the SQL Server database files(mdf and ldf) are located, using a query. You can use system procedure sp_helpdb and system view sysfiles to obtain this information.
The following methods shows the path of the database files for master database
EXEC sp_helpdb master
Method 2 : Use sys.sysfiles view
select filename from master.sys.sysfiles