LLI Wiki — My Digital Knowledge Base

Change the default data and log paths of SQL Server

Change the default folders for new data and log files of a SQL Server instance with xp_instance_regwrite.

The default locations for new data and log files are stored in the instance registry, under HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer\MSSQLServer. The extended stored procedure xp_instance_regwrite writes these values.

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE'
    , N'Software\Microsoft\MSSQLServer\MSSQLServer'
    , N'DefaultData'
    , REG_SZ
    , N'C:\SQL\Data'
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE'
    , N'Software\Microsoft\MSSQLServer\MSSQLServer'
    , N'DefaultLog'
    , REG_SZ
    , N'C:\SQL\Logs'
GO

Notes

Mastodon LLIMastodon SocialFosstodon