Wednesday, February 27, 2013

rename stored proceedure

hi,

do not rename a stored procedure using sp_rename ,
its best idea to alter the  stored procedure, script out and save the code,then drop the stored procedure and recreate the stored procedure again  ,

ex:

CREATE PROCEDURE sp_test
AS
SELECT
* FROM dbo.test

GO

Rename:
sp_rename 'SP_test', 'SP_test2'


USE DBNAME
GO
sp_helptext  sptest2

We will see the name of the stored procedure is the old name and not the new name but when we try to access the old name

 USE DBNAME
GO
sp_helptext  sptest

 there is an error that sp not found. 

NOTE:
This happens because when the store procedure is renamed,  the sys.procedures system table is not getting updated. The only solution to this is to drop the stored procedure and re-create it with the new name.

Thanks 

No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...