Rename a Stored Procedure
This topic describes how to rename a stored procedure in SQL Server 2019 (15.x) by using SQL Server Management Studio or Transact-SQL.
In This Topic
Before you begin:
To rename a stored procedure, using:
Before You Begin
Limitations and Restrictions
Procedure names must comply with the rules for identifiers.
Renaming a stored procedure retains the
object_idand all the permissions that are specifically assigned to the procedure. Dropping and recreating the object creates a new
object_idand removes any permissions specifically assign to the procedure.
Renaming a stored procedure does not change the name of the corresponding object name in the definition column of the sys.sql_modules catalog view. To do that, you must drop and re-create the stored procedure with its new name.
Changing the name or definition of a procedure can cause dependent objects to fail when the objects are not updated to reflect the changes that have been made to the procedure. For more information, see View the Dependencies of a Stored Procedure.
Requires CREATE PROCEDURE permission in the database and ALTER permission on the schema in which the procedure is being created, or requires membership in the db_ddladmin fixed database role.
Requires ALTER permission on the procedure or requires membership in the db_ddladmin fixed database role.
Using SQL Server Management Studio
To rename a stored procedure
- In Object Explorer, connect to an instance of Database Engine and then expand that instance.
- Expand Databases, expand the database in which the procedure belongs, and then expand Programmability.
- Determine the dependencies of the stored procedure.
- Expand 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.
To rename a stored procedure
- Connect to the Database Engine.
- From the Standard bar, click New Query.
- Copy and paste the following example into the query window and click Execute. This example shows how to rename a procedure by dropping the procedure and re-creating the procedure with a new name. The first example creates the stored procedure
'HumanResources.uspGetAllEmployeesTest. The second example renames the stored procedure to
--Create the stored procedure. USE AdventureWorks2012; GO CREATE PROCEDURE HumanResources.uspGetAllEmployeesTest AS SET NOCOUNT ON; SELECT LastName, FirstName, Department FROM HumanResources.vEmployeeDepartmentHistory; GO --Rename the stored procedure. EXEC sp_rename 'HumanResources.uspGetAllEmployeesTest', 'uspEveryEmployeeTest';
ALTER PROCEDURE (Transact-SQL)
CREATE PROCEDURE (Transact-SQL)
Create a Stored Procedure
Modify a Stored Procedure
Delete a Stored Procedure
View the Definition of a Stored Procedure
View the Dependencies of a Stored Procedure