下面这段SQL code是获取SQL Server默认的备份目录,创建一个用户自定义函数。
代码
IF OBJECT_ID('dbo.udf_SQLServerBackupDirectory') IS NOT NULL
DROP FUNCTION dbo.udf_SQLServerBackupDirectory
GO
CREATE FUNCTION dbo.udf_SQLServerBackupDirectory()
RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE @Result NVARCHAR(4000)
EXECUTE [master].[dbo].xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory',
@Result OUTPUT,
'NO_OUTPUT'
RETURN @Result
END
DROP FUNCTION dbo.udf_SQLServerBackupDirectory
GO
CREATE FUNCTION dbo.udf_SQLServerBackupDirectory()
RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE @Result NVARCHAR(4000)
EXECUTE [master].[dbo].xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory',
@Result OUTPUT,
'NO_OUTPUT'
RETURN @Result
END
获取这个自定义函数值,即是得到SQL Server默认备份目录。
SELECT dbo.udf_SQLServerBackupDirectory()