The stored procedure "master.sys.xp_instance_regwrite" is not documented in SQL Server Books Online (BOL), but is usefull. In general the syntax isEXECUTE [master].[sys].[xp_instance_regwrite]
@rootkey = N'<name of root key>'
,@key = N'<key name>'
,@value_name = N'<key name value>'
,@type = N'<key type>'
,@value = <key value>;
For example the number of SQL Server Errorlog files can be updated by the statementEXECUTE [master].[sys].[xp_instance_regwrite]
@rootkey = N'HKEY_LOCAL_MACHINE'
,@key = N'Software\Microsoft\MSSQLServer\MSSQLServer'
,@value_name = N'NumErrorLogs'
,@type = N'REG_DWORD'
,@value = 42;
The parameter @type
takes a value without N'' around (@type = <key type>
), but I like the Unicode framing. This way I try to avoid difficulties when building the values outside the call.