There are two approaches to rename stored procedure.
Dropping and Recreating Procedure :
The problem is it will lead to losing of permissions.
sp_rename of Procedure : Permissions will remain intact. The stored procedure will be renamed. But, sys.sql_modules will still be having the old definition.
I prefer the second approach.
I followed the below steps:
- Have copy of the stored Procedure content Rename the stored procedure
1: EXEC sp_rename 'dbo.OldStoredProcedureName','NewStoredProcedureName'
2: GO
- ALTER PROCEDURE to have the modified code of the procedure in the sys.sql_modules
1: ALTER PROCEDURE dbo.NewStoredProcedureName
- Now, Stored procedure name is also updated and code is refreshed in sys.sql_modules and permissions are also intact.
No comments:
Post a Comment