Home > SQL Server Tips > Database Development > Undocumented stored procedures: Registry manipulation in SQL Server 7.0 and 2000
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE DEVELOPMENT

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


Serdar Yegulalp, Contributor
07.29.2005
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

xp_regread

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

EXEC xp_regread 
@rootkey=,@key=,@value_name=, 
@value= OUTPUT

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 
@rootkey='HKEY_LOCAL_MACHINE',@key='SOFTWARE\MyKey',@value_
name='MyValue', @value=@outvar OUTPUT

xp_regwrite

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

EXEC xp_regwrite 
@rootkey=,@key=,@value_name=, 
@type=, @value=

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

xp_regdeletekey

Function xp_regdeletekey removes an entire key:

EXEC xp_regdeletekey @rootkey=,@key=

xp_regdeletevalue

Function xp_regdeletevalue deletes a single value:

EXEC xp_regdeletevalue @rootkey=,@key=, 
@value_name=

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 SearchSQLServer.com

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


  • Rate this Tip
    To rate tips, you must be a member of SearchSQLServer.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



    RELATED CONTENT
    Database Development
    Using DELETE and TRUNCATE TABLE statements to delete data in SQL Server
    Speed up reports in SQL Server Reporting Services with caching
    Data Transformation Services vs. SSIS: The key differences
    Working with IntelliSense in SQL Server 2008 Management Studio
    Top tips and tricks for SQL Server database development
    Managing the development lifecycle with Visual Studio Team System 2008
    Processing XML files with SQL Server functions
    A first look at Visual Studio Team System 2008 Database Edition
    How to create a SQL inner join and outer join: Basics to get started
    New datetime data types in SQL Server 2008 offer flexibility

    SQL Server Stored Procedures
    SQL Server Mailbag: CALs, witnesses and unwanted changes
    SQL Server Mailbag: Stored procedures, triggers and SSRS reports
    Top tips and tricks for SQL Server database development
    Top 10 SQL Server development tips of 2008
    SQL Server trigger vs. stored procedure to receive data notification
    SQL Server errors, failures and other problems fixed from the trenches
    SQL Server and data manipulation in T-SQL
    How to use SQL Server 2008 hierarchyid data type
    SQL Server stored procedures tutorial: Write, tune and get examples
    Check SQL Server database and log file size with this stored procedure

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    library  (SearchSQLServer.com)
    trigger  (SearchSQLServer.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



    SQL Server Development - .NET, C#, T-SQL, Visual Basic
    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts