SQL Query to Rename Stored Procedure
Last Updated :
28 Oct, 2021
Stored Procedure is a saved SQL code. It is created to save time as we can use it again and again without writing the whole query. In this article, we will see how to Rename a Stored Procedure.
To create a Procedure:
Syntax:
CREATE PROCEDURE procedure_name AS
SELECT * FROM table_name;
SQL query whose procedure needs to be created is always written after the AS statement.
To execute procedure:
Syntax:
EXEC procedure_name;
We can perform the above action by two methods. Those methods are:
- By using sp_rename statement in SQL Server.
- From Object Explorer in SQL Server Management Studio(SSMS).
For demonstration follow the below steps:
Step 1: Create a database
The database can be created using CREATE command.
Query:
CREATE DATABASE geeks;
Step 2: Using a database
Use the below SQL statement to switch the database context to geeks:
Query:
USE geeks;
Step 3: Table definition
We have the following demo_table in our geek's database.
Query:
CREATE TABLE demo_table(
NAME VARCHAR(20),
AGE INT,
CITY VARCHAR(20) );
Step 4: Insert data into a table
Query:
INSERT INTO demo_table VALUES
('ROMY KUMARI', 22, 'NEW DELHI'),
('RINKLE ARORA',23, 'PUNJAB'),
('AKANKSHA GUPTA',22, 'PUNJAB'),
('SUJATA JHA', 30,'PATNA'),
('PREETI GIRI', 26,'BANGLORE'),
('PREM GUPTA',31,'PUNE');
Output:

Step 5: Create procedure
We will create a procedure called 'Display' to view all the content of the table.
Query:
CREATE PROCEDURE Display AS
SELECT * FROM demo_table;
Output:

Step 6: Rename Procedure
Method 1: using sp_rename
Syntax:
EXEC sp_rename 'Current procedure_name', 'New procedure_name';
For demonstration let's rename the procedure name from 'Display' to 'Show'.
Query:
EXEC sp_rename 'Display', 'Show';
Execute:
EXEC Show;
Output:

Method 2: From Object Explorer
Step 1: Open object Explorer from View option in the menu bar. It appears on the left side of the screen.

We can see the 'geeks' database inside the database folder.
Step 2: Expand the Programmability folder inside the geek's database. Then expand the Stored procedure folder

Step 3: Right-click on the procedure created and select the 'Rename' option.

Step 4: Type the name with which you want to rename the procedure

In these two ways, we can rename the stored procedure.
Similar Reads
SQL Stored Procedures Stored procedures are precompiled SQL statements that are stored in the database and can be executed as a single unit. SQL Stored Procedures are a powerful feature in database management systems (DBMS) that allow developers to encapsulate SQL code and business logic. When executed, they can accept i
7 min read
SQL Query to Rename Database Renaming a database in SQL is an essential task that database administrators and developers frequently perform. Whether youâre reorganizing your data, correcting naming conventions, or simply updating your project structure, knowing how to rename a database properly is critical. In this article, we'
4 min read
How to Search Text in a SQL Server Stored Procedure A stored procedure is a compiled SQL code that is saved in the database and can be reusable by calling this from a Client Application or another stored procedure. When there are tens and hundreds of stored procedures and if a programmer wants to find out if there is a stored procedure for some speci
6 min read
How to SELECT FROM Stored Procedure in SQL Stored procedures are precompiled SQL queries stored in the database that encapsulate logic and can accept parameters, perform operations and return results. They are widely used in SQL for encapsulating reusable logic, improving performance and enhancing security. In this article, weâll explore how
4 min read
How to Modify a Stored Procedure in SQL Server? In this article, we will learn to modify the created stored procedure in MS SQL.You can modify the Stored Procedure in two ways. one is by using a client called SSMS and other way is by using T-SQL statements + SSMS in MS SQL Server. Method 1: Using SQL Server Management Studio (SSMS) to Modify the
3 min read
Some Useful System Stored Procedures in SQL Some Useful System Stored Procedures in SQL. These procedures are built-in procedures and will help to extract the definition and dependencies of the existing user-defined stored procedures. sp_help : This will display the Stored procedure Name, Schema Name, created date, and Time or if there are an
2 min read