locked
Best Method to Copy and Rename a Stored Procedure RRS feed

  • Question

  • Hello, what is the best method to copy an existing stored procedure and rename so I can make minor modifications to the newly renamed copy? The one I want to reuse is exactly what I need but need to give the copied SPROC a new name and a new internal value, as it's used to help trigger a job once a table is loaded. Thank you, JPQ
    Wednesday, February 22, 2017 8:08 PM

Answers

  • Please don't ask "best" questions. That implies your reader has a relatively good idea of how you quantify "best". Given your description, I'll choose "easiest".

    In SSMS, navigate to your existing procedures in the object explorer. Right-click on the procedure, select <Script stored procedure as>, <create to>, <new query editor window>. In that new query window, change the name of the procedure as you see fit and then execute the query by clicking on the Execute button toolbar.

    • Proposed as answer by Naomi N Wednesday, February 22, 2017 8:21 PM
    • Marked as answer by JP_Quinn Thursday, February 23, 2017 2:53 PM
    Wednesday, February 22, 2017 8:20 PM

All replies

  • Please don't ask "best" questions. That implies your reader has a relatively good idea of how you quantify "best". Given your description, I'll choose "easiest".

    In SSMS, navigate to your existing procedures in the object explorer. Right-click on the procedure, select <Script stored procedure as>, <create to>, <new query editor window>. In that new query window, change the name of the procedure as you see fit and then execute the query by clicking on the Execute button toolbar.

    • Proposed as answer by Naomi N Wednesday, February 22, 2017 8:21 PM
    • Marked as answer by JP_Quinn Thursday, February 23, 2017 2:53 PM
    Wednesday, February 22, 2017 8:20 PM
  • you do not need to rename a SP if you copied it (you can direct give it a name) or as @scott suggested. however you can rename a SP by executing below command.

    
    
    Exec sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'   
        [ , [ @objtype = ] 'object_type' ]


    Thursday, February 23, 2017 8:56 AM