1. Select filename from master. Sysfiles
2. Master. Xp_instance_regread n ' HKEY_LOCAL_MACHINE ', n ' software\microsoft\mssqlserver\setup ', n ' SQLPath '
--Get the various directories in SQL
DECLARE @path varchar (8000)
--Get the data file path of the current database
Select @path =rtrim (reverse (filename)) from Sysfiles
Select @path =reverse (substring (@path, charindex (' \ ', @path), 8000))
Select data file directory [email protected]
--Get the data file path set at SQL installation
Select @path =rtrim (reverse (filename)) from master: Sysfiles where name= ' master '
Select @path =reverse (substring (@path, charindex (' \ ', @path), 8000))
Select SQL data Files directory [email protected]
--Get the default backup directory according to the installation path:
Select @path =rtrim (reverse (filename)) from master: Sysfiles where name= ' master '
Select @path =substring (@path, charindex (' \ ', @path) +1,8000),
@path =reverse (substring (@path, charindex (' \ ', @path), 8000) + ' backup\ '
Select SQL Default backup directory [email protected]
-Read registry Hkey_local_machine\software\microsoft\mssqlserver\setup
declare @path varchar ($)
exec master.dbo.xp_regread
' HKEY_LOCAL_MACHINE ',
' Software\microsoft\mssqlserver\ Setup ',
' SQLPath ', @path output
set @path = @path + ' \data\ '
print @path