Wednesday, March 21, 2012

How to change default database 'root directory' ?

Hi folks,

Can you please tell me how should I change the default root directory (used for db storage) in SQL 2005 Std. Edition. ?

Currently its configured to:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL
and I want to change the drive letter here.

Thanks in advance.
Cyk

-- Try this:

declare @.SmoRoot nvarchar(512)
exec master.dbo.xp_instance_regread
'HKEY_LOCAL_MACHINE'
,'SOFTWARE\Microsoft\MSSQLServer\Setup'
,'SQLPath'
,@.SmoRoot OUTPUT

print 'Old root dir: '+ @.SmoRoot

set @.SmoRoot = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL'

exec master.dbo.xp_instance_regwrite
'HKEY_LOCAL_MACHINE'
,'SOFTWARE\Microsoft\MSSQLServer\Setup'
,'SQLPath'
,REG_SZ
,@.SmoRoot

exec master.dbo.xp_instance_regread
'HKEY_LOCAL_MACHINE'
,'SOFTWARE\Microsoft\MSSQLServer\Setup'
,'SQLPath'
,@.SmoRoot OUTPUT

print 'New root dir: '+ @.SmoRoot

-- Bo

No comments:

Post a Comment