SQL Server:如何选择安装路径? [英] SQL Server: How to SELECT the installation path?
问题描述
我知道有一个变量、函数或存储过程可以用来查找 SQL Server 的安装路径:
i know there is a variable, function, or stored procedure that you can use to find the path that SQL Server is installed to:
例如:
c:\Program Files\Microsoft SQL Server\MSSQL.7\MSSQL
或
m:\CustomInstance\MSSQL
<小时>
实际上,我希望选择默认备份路径.但由于我怀疑它是否存在,我将把 \BACKUP 附加到安装路径上,并称其足够接近.
In reality, i'm hoping to SELECT for the default backup path. But since i doubt that exists, i'll just tack \BACKUP onto the install path and call it close enough.
select filename from sysaltfiles
where name = db_name()
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sysaltfiles'.
<小时>
select filename from master.dbo.sysaltfiles
where name = db_name()
filename
----------------
(0 row(s) affected)
推荐答案
如何选择安装路径
注意:xp_instance_regread 不会读取您指定的注册表项,而是将该键路径转换为您指定的特定 SQL Server 实例的适当路径.正在运行.换句话说:xp_regread 在 xp_instance_regread 成功的地方失败.
How to select the installation path
Note: xp_instance_regread doesn't read the registry key you specify, but instead converts that key path into the appropriate path for the specific SQL Server instance you're running on. In other words: xp_regread fails where xp_instance_regread succeeds.
declare @rc int, @dir nvarchar(4000)
exec @rc = master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\Setup',
N'SQLPath',
@dir output, 'no_output'
select @dir AS InstallationDirectory
SQL Server 备份目录
declare @rc int, @dir nvarchar(4000)
exec @rc = master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',
N'BackupDirectory',
@dir output, 'no_output'
select @dir AS BackupDirectory
这篇关于SQL Server:如何选择安装路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!