Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
SQL database in Microsoft Fabric
This topic describes how to rename a stored procedure in SQL Server by using SQL Server Management Studio or Transact-SQL.
In This Topic
Before you begin:
To rename a stored procedure, using:
Procedure names must comply with the rules for identifiers.
Renaming a stored procedure retains the object_id
and all the permissions that are specifically assigned to the procedure. Dropping and recreating the object creates a new object_id
and 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.
CREATE 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.
ALTER PROCEDURE
Requires ALTER permission on the procedure or requires membership in the db_ddladmin fixed database role.
'HumanResources.uspGetAllEmployeesTest
. The second example renames the stored procedure to HumanResources.uspEveryEmployeeTest
.--Create the stored procedure.
USE AdventureWorks2022;
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
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Create stored procedures and user-defined functions - Training
This content is a part of Create stored procedures and user-defined functions.