Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I edit a stored procedure?

I have several stored procedures in my database, structured like this:

CREATE PROCEDURE MyProcedure (.....)
AS
    DECLARE @myvar NVARCHAR(100);
    SET @myvar = (SELECT .... FROM my_table WHERE ....)
GO

I was asked to replace the table my_table in the FROM clause with another one in every procedure that has it.

I went through a lot of researches, but I should create a script that works by itself, and I haven't found anything suitable. For example I found the sp_helpTetx that shows the source code of a stored procedure, but is there a way to put it into a variable in order to edit it?

like image 204
Phate01 Avatar asked Mar 10 '15 10:03

Phate01


People also ask

How do I edit a stored procedure in mysql?

To modify an existing stored routine (procedure or function), double-click the node of the routine to modify, or right-click this node and choose the Alter Routine command from the context menu. Either of the commands opens the SQL Editor. Routine properties can be viewed in the Properties window.

Can we alter stored procedure in mysql?

More than one change may be specified in an ALTER PROCEDURE statement. However, you cannot change the parameters or body of a stored procedure using this statement; to make such changes, you must drop and re-create the procedure using DROP PROCEDURE and CREATE PROCEDURE .

How do you modify a procedure in Oracle?

The procedure must be in your own schema or you must have ALTER ANY PROCEDURE system privilege. Specify the schema containing the procedure. If you omit schema , then Oracle Database assumes the procedure is in your own schema. Specify the name of the procedure to be recompiled.

How do I open a stored procedure in SQL Server?

Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.


1 Answers

You can use tool like REDGATE SqlRefactor that works perfectly or you can script all the stored procedures, replace CREATE command with ALTER and then apply the other REPLACE in text you need...

I do it lot of time, you have to pay attention but it works...

like image 71
DarioN1 Avatar answered Sep 22 '22 18:09

DarioN1