---
title: "In SQL, how do you change the name of a stored procedure?"  
description: "In SQL, how do you change the name of a stored procedure?"  
author: "Steilla Mitchel"  
published: 2023-08-30  
updated: 2023-08-31  
canonical: https://www.mindstick.com/forum/159769/in-sql-how-do-you-change-the-name-of-a-stored-procedure  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# In SQL, how do you change the name of a stored procedure?

In [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database), how do you change the [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) of a [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net)?

## Replies

### Reply by Aryan Kumar

There are two ways to change the name of a [stored](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) [procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) 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`:

SQL

```plaintext
sp_rename 'GetCustomers', 'GetCustomers2';
```

SQL

```plaintext
sp_rename 'old_stored_procedure_name', 'new_stored_procedure_name';
```

## Using the ALTER PROCEDURE statement:

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

```plaintext
ALTER PROCEDURE GetCustomers2 AS
  BEGIN
    SELECT * FROM Customers;
  END;
```

SQL

```plaintext
ALTER PROCEDURE new_stored_procedure_name AS
  BEGIN
    ...
  END;
```


---

Original Source: https://www.mindstick.com/forum/159769/in-sql-how-do-you-change-the-name-of-a-stored-procedure

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
