The default data path is stored in the registry not in a SQL server table. In SQL 2000 it is the DefaultData value in the following key. Look for a similar key in earlier versions.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer Terry L. Broadbent - DBA
Computing Links:
Hi McDonald,
This may not be the correct way of doing it. But you can try it.
If we believe that wherever the data and log files are stored for MASTER database in SQL Server as DEFAULT PATH for databases, then you can use this.
SYSDATABASES has filenames, database names etc..
--gives the database name,data filename for all databases
select name,filename from sysdatabases
--database name, filepath for master database
select name,filename from sysdatabases where name='master'
--(1)
--this is to get the path of master data file
select reverse(substring(reverse(filename),charindex('\',reverse(filename),1),len(filename)))
from sysdatabases where name='master'
to get the path from filename, u can make good logic to extract the required path.
--there you go
--i got one more idea to extract it simply
--because we know the datafile name for MASTER
--(2)
select replace(filename,'MASTER.MDF','') from sysdatabases where name='master'
Statements (1) and (2) will give the same result.
But I am not sure whether is correct to extract the DEFAULT PATH from sysdatabases.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.