Home > SQL Server Tips > Stored Procedures > Upgrading stored procedures in SQL Server 2005
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

STORED PROCEDURES

Upgrading stored procedures in SQL Server 2005


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


Expert advice on database development
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


I recently explained how changes in SQL Server 2005 may break older applications and databases, especially where deprecated functions are used. Now I'm going to discuss how to use stored procedures in your migrated databases to take advantage of newer functionality in SQL Server 2005 without breaking existing functionality.

Let's say you have a front-end application that's being written or managed by a different team and it isn't upgraded as often as the back-end database. You still want to make changes in your SQL Server application's stored procedures to take advantage of newer features. You also want to do this as gracefully as possible so the database and front-end application don't have a falling out.

For example, you may want to update a stored procedure to use some new functions available to T-SQL in SQL Server 2005, such as the TRY and CATCH functions, which make sophisticated error trapping a lot easier. You'd normally copy the existing stored procedure into a new, parallel stored procedure, update it to use the new functions and then test the behavior of the two side-by-side through either a modified version of the front-end application (if it's available) or Query Analyzer.

When you're confident the new stored procedure is behaving as it should and it is ready to be used in production, you can swap it in seamlessly either by renaming the two stored procedures or by copying in the code. I personally prefer doing a rename, since that allows you to have a backup copy of the old code -- backed up with your database like everything else in case you run into an unexpected wrinkle.

This is a fairly standard technique, but one of the more interesting wrinkles I've seen on it involves the passing of an optional parameter:

CREATE PROCEDURE my_procedure

{other parameters go here},
@optionalparameter Boolean=FALSE

AS

If @optionalparameter=TRUE
Begin
 {NEW version of stored procedure with SQL Server 2005-specific commands goes here}
End
Else
Begin
 {OLD version of stored procedure goes here}
End
There is another useful way to selectively test the code. Existing front-end calls to the stored procedure will not use the optional parameter and will execute old code. You can test the stored procedure in place using new front-end code and then gracefully upgrade existing references to the stored procedure as you go. Since the parameter is optional all the existing calls to the stored procedure (i.e., those without the parameter) will go through exactly as before.

If you aren't allowed to add new stored procedures but are allowed to modify existing ones, this is a good way to work around such a limitation. When no legacy code remains, you can then phase out the IF in the stored procedure. Lastly, deprecate the optional parameter in both the stored procedure and your front-end code.

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: Tuning stored procedures: Structured exception handling in SQL Server 2005
  • Tip: SQL Profiler: Features, functions and setup in SQL Server 2005
  • SQL Server Clinic: T-SQL performance problems and solutions

  • 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    Add to Google


    RELATED CONTENT
    Stored Procedures
    Check SQL Server database and log file size with this stored procedure
    Configure SQL Server Service Broker for sending stored procedure data
    Find size of SQL Server tables and other objects with stored procedure
    Stored procedure to monitor long-running jobs in SQL Server 2000
    Make changes to SQL Server stored procedures with batch editing
    Stored procedure to find fragmented indexes in SQL Server
    Use table-valued parameters for SPs in SQL Server 2008
    Examples of SQL Server stored procedures and parameters
    Top 10 SQL Server development questions
    FAQ: SQL Server stored procedure how-tos

    SQL Server stored procedures
    SQL Server trigger vs. stored procedure to receive data notification
    How to use SQL Server 2008 hierarchyid data type
    SQL and SQL Server Tutorial and Reference Guide
    SQL Server stored procedures tutorial: Write, tune and get examples
    Check SQL Server database and log file size with this stored procedure
    SQL Server source code analysis and management adds database security
    Configure SQL Server Service Broker for sending stored procedure data
    Find size of SQL Server tables and other objects with stored procedure
    Track changes to SQL Server 2000 and 2005 with one simple utility
    Troubleshoot SQL Server 2005 temporary table performance problems

    SQL Server 2005 (Yukon)
    Tips for tuning SQL Server 2005 to improve reporting performance
    Using DATEADD and DATEDIFF to calculate SQL Server datetime values
    SQL Server consolidation: Why it's an optimization technique
    Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
    Using SQL Server datetime functions GETDATE, DATENAME and DATEPART
    SSIS error message due to installation problem on SQL Server 2005
    SQL Server data conversions from date/time values to character types
    Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
    How to configure Database Mail in SQL Server 2005 to send mail
    How to use rank function in SQL Server 2005
    SQL Server 2005 (Yukon) Research

    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.

    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




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