/*
說明:如果查詢路徑返回的值是null,說明在默認安裝路徑下即
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA
*/
--查詢用戶庫Data文件默認路徑:
DECLARE @DefaultData VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='DefaultData',
@DefaultData=@DefaultData OUTPUT
SELECT @DefaultData
go
--查詢用戶庫Log文件默認路徑:
DECLARE @DefaultLog VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='DefaultLog',
@DefaultLog=@DefaultLog OUTPUT
SELECT @DefaultLog
go
--查詢用戶庫備份文件默認路徑:
DECLARE @BackupDirectory VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='BackupDirectory',
@BackupDirectory=@BackupDirectory OUTPUT
SELECT @BackupDirectory
go
--修改用戶庫Data文件默認路徑:
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='DefaultData',
@type='REG_SZ',
@value='c:\test\data'
go
--修改用戶庫Log文件默認路徑:
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='DefaultLog',
@type='REG_SZ',
@value='c:\test\log'
--修改用戶庫備份文件默認路徑:
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer',
@value_name='BackupDirectory',
@type='REG_SZ',
@value='D:\test\backup'
go
查看本欄目