Problem solve Get help with specific problems with your technologies, process and projects.

Undocumented stored procedures: Registry manipulation in SQL Server 7.0 and 2000

Among the many undocumented functions you'll find in SQL Server 7.0 and 2000 is a set of extended stored procedures to obtain, set and delete Registry keys. Contributor Serdar Yegulalp explains when and how to use these procedures.

You'll find a slew of undocumented functions in SQL Server 7.0 and 2000, most of them used by Microsoft to perform internal tasks that might change from version to version of the product.

Among these undocumented functions are a set of extended stored procedures used by SQL Server itself to obtain, set and delete Registry keys. This can come in handy if you're creating a SQL Server application that also has standalone binary components, and you want to use the Registry to track program settings between both the application and your database.


Function xp_regread reads a key from the Registry and writes the results to a user-supplied variable.

EXEC xp_regread 


Here is a variable to write the resulting key information. For instance, to read the value MyValue from SOFTWARE\MyKey in HKEY_LOCAL_MACHINE, and store the results in @outvar, you would use:

EXEC xp_regread 
name='MyValue', @value=@outvar OUTPUT


Function xp_regwrite writes a value to the Registry and works in much the same way.

EXEC xp_regwrite 
     , @value=


Keytype @type is, of course, one of the standard keytypes, such as REG_SZ.


Function xp_regdeletekey removes an entire key:

EXEC xp_regdeletekey @rootkey= ,@key=


Function xp_regdeletevalue deletes a single value:

EXEC xp_regdeletevalue @rootkey=


Use extreme caution when deleting keys, since it is entirely possible for you to delete keys used by other applications or the system. Note also that you may not be able to run any of these extended stored procedures without having administrative authority in SQL Server (i.e., the sa context or something similar to it).

About the author: Serdar Yegulalp is editor of the Windows Power Users Newsletter. Check it out for the latest advice and musings on the world of Windows network administrators -- and please share your thoughts as well!

More information from

  • Tip: Undocumented sp_gettypestring stored procedure
  • Tip: Find space occupied by all tables and indexes
  • Learning Center: Stored procedures

  • Dig Deeper on SQL Server Stored Procedures

    Start the conversation

    Send me notifications when other members comment.

    Please create a username to comment.