There are two ways to change the name of a storedprocedure in SQL:
Using the sp_rename system stored procedure:
The sp_rename system stored procedure can be used to rename any object in a SQL Server database, including stored procedures. The syntax for the
sp_rename system stored procedure is:
The old_stored_procedure_name is the name of the stored procedure that you want to rename. The
new_stored_procedure_name is the new name for the stored procedure.
For example, the following statement will rename the stored procedure GetCustomers to
GetCustomers2:
The ALTER PROCEDURE statement can be used to change the name of a stored procedure, as well as other properties of the stored procedure. The syntax for the
ALTER PROCEDURE statement is:
The new_stored_procedure_name is the new name for the stored procedure. The
BEGIN and END keywords delimit the body of the stored procedure.
For example, the following statement will rename the stored procedure GetCustomers to
GetCustomers2 and also change the body of the stored procedure:
It is important to note that you cannot rename a stored procedure that is being used by another object, such as a view or a stored procedure.
Here are some additional things to keep in mind when renaming a stored procedure:
The sp_rename system stored procedure is a Transact-SQL statement. Transact-SQL statements are not reversible, so it is important to make sure that you are renaming the correct stored procedure.
You cannot rename a stored procedure that is being used by another object, such as a view or a stored procedure.
If you are renaming a stored procedure that is a user-defined function, you need to update any references to the stored procedure in other objects.
SQL
ALTER PROCEDURE GetCustomers2 AS
BEGIN
SELECT * FROM Customers;
END;
SQL
ALTER PROCEDURE new_stored_procedure_name AS
BEGIN
...
END;
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
There are two ways to change the name of a stored procedure in SQL:
Using the sp_rename system stored procedure:
The
sp_renamesystem stored procedure can be used to rename any object in a SQL Server database, including stored procedures. The syntax for thesp_renamesystem stored procedure is:The
old_stored_procedure_nameis the name of the stored procedure that you want to rename. Thenew_stored_procedure_nameis the new name for the stored procedure.For example, the following statement will rename the stored procedure
GetCustomerstoGetCustomers2:SQL
SQL
Using the ALTER PROCEDURE statement:
The
ALTER PROCEDUREstatement can be used to change the name of a stored procedure, as well as other properties of the stored procedure. The syntax for theALTER PROCEDUREstatement is:The
new_stored_procedure_nameis the new name for the stored procedure. TheBEGINandENDkeywords delimit the body of the stored procedure.For example, the following statement will rename the stored procedure
GetCustomerstoGetCustomers2and also change the body of the stored procedure:It is important to note that you cannot rename a stored procedure that is being used by another object, such as a view or a stored procedure.
Here are some additional things to keep in mind when renaming a stored procedure:
sp_renamesystem stored procedure is a Transact-SQL statement. Transact-SQL statements are not reversible, so it is important to make sure that you are renaming the correct stored procedure.SQL
SQL