Get SQL Server installation path to various directories

Source: Internet
Author: User
Tags mssqlserver rtrim

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.