Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I rename many Stored Procedures without breaking stuff?

My database has had several successive maintainers over the years and any naming guidelines that may have once been in place have been ignored.

I'd like to rename the stored procedures to a consistent format. Obviously I can rename them from within SQL Server Management Studio, but this will not then update the calls made in the website code behind (C#/ASP.NET).

Is there anything I can do to ensure all calls get updated to the new names, short of searching for every single old procedure name in the code? Does Visual Studio have the ability to refactor such stored procedure names?

NB I do not believe my question to be a duplicate of this question as the latter is solely about renaming within the database.

like image 811
fearoffours Avatar asked Jul 22 '10 12:07

fearoffours


People also ask

How do I change the name of a stored procedure?

To rename a stored procedureExpand Stored Procedures, right-click the procedure to rename, and then click Rename. Modify the procedure name. Modify the procedure name referenced in any dependent objects or scripts.

Can there be more than one procedure with the same name?

Yes, two or more procedures can have the same name. This is also known as polymorphism which is a core principle of Object Oriented Programming. Procedures are written for code reuse and to prevent the same code repetition. So they can be called as many times as required by the program.

How many stored procedures can be called from a stored procedure?

Single Stored Procedure per CALL StatementA single executable statement can call only one stored procedure. In contrast, a single SQL statement can call multiple functions. Similarly, a stored procedure, unlike a function, cannot be called as part of an expression.


1 Answers

You could make the change in stages:

  1. Copy of the stored procedures to the new stored procedures under their new name.
  2. Alter the old stored procedures to call the new ones.
  3. Add logging to the old stored procedures when you've changed all the code in the website.
  4. After a while when you're not seeing any calls to the old stored procedures and you're happy you've found all the calls in the web site, you can remove the old stored procedures and logging.
like image 179
John Warlow Avatar answered Sep 22 '22 21:09

John Warlow