How to Execute SQL Server Stored Procedure in SQL Developer?
Last Updated :
23 Sep, 2021
A stored procedure is a set of (T-SQL ) statements needed in times when we are having the repetitive usage of the same query. When there is a need to use a large query multiple times we can create a stored procedure once and execute the same wherever needed instead of writing the whole query again.
In this article let us see how to execute SQL Server Stored Procedure in MSSQL.
Syntax: For creating a stored procedure
CREATE PROCEDURE (or CREATE PROC) proc_name
AS
BEGIN
QUERY
END
Step 1: We creating a Database. For this use the below command to create a database named GeeksforGeeks.
Query:
CREATE DATABASE GeeksforGeeks;
Output:

Step 2:To use the GeeksforGeeks database use the below command.
Query:
USE GeeksforGeeks
Output:

Step 3:Now we creating a table. Create a table student_details with 3 columns using the following SQL query.
Query:
CREATE TABLE student_details(
stu_id VARCHAR(8),
stu_name VARCHAR(20),
stu_cgpa DECIMAL(4,2) );
Output:

Step 4: The query for Inserting rows into the Table. Inserting rows into student_details table using the following SQL query.
Query:
INSERT INTO student_details VALUES('40001','PRADEEP',9.6);
INSERT INTO student_details VALUES('40002','ASHOK',8.2);
INSERT INTO student_details VALUES('40003','PAVAN KUMAR',7.6);
INSERT INTO student_details VALUES('40004','NIKHIL',8.2);
INSERT INTO student_details VALUES('40005','RAHUL',7.0);
Output:

Step 5: Viewing the inserted data
Query:
SELECT * FROM student_details;
Output:

- Query to create a stored procedure to view the table:
Query:
CREATE PROCEDURE view_details
AS
BEGIN
SELECT * FROM student_details;
END
Output:
For executing a stored procedure we use the below syntax:
Syntax:
EXEC proc_name
or
EXECUTE proc_name
or
proc_name
Query:
EXECUTE view_details
Output:

- Query to create a stored procedure that takes the argument as stu_id and displays the cgpa of that id.
Query:
CREATE PROCEDURE get_student_cg_details
@stu_id VARCHAR(20)
AS
BEGIN
SELECT stu_id, stu_cgpa FROM student_details
WHERE stu_id= @stu_id
END
Output:

Query:
EXECUTE get_student_cg_details '40002'
Output:
Similar Reads
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
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 SQL Select from Stored Procedure using SQL Server? There may be situations in SQL Server where you need to use a stored procedure to get data from a SQL query. For direct data selection from a stored procedure within a query, SQL Server offers options like OPENQUERY and OPENROWSET. The usual way is running the stored procedure independently and then
3 min read
How to Create and Call a Stored Procedure in SQL? With this article, we will learn how to Create and Call a Stored Procedure in SQL. For this article, we are going to use MSSQL as our database server. What is a Stored Procedure?A stored procedure is a pre-written SQL query that can be called multiple times and will run as the same. Like we can crea
2 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 Write a Simple SELECT Stored Procedure in PL/SQL? In PL/SQL, stored procedures are powerful tools for encapsulating logic and executing complex queries. This article will guide you through the process of creating a simple SELECT stored procedure in PL/SQL. In this article, we will learn how to store procedures with the help of various methods and e
6 min read
Pass DataTable to Stored Procedure as Parameter in SQL Server In SQL Server, when we have to pass multiple rows of data to be added or updated in a table the simplest way to send data from the front-end application to the database is by using DataTable as a parameter sent to a stored procedure. Any number of data records can be sent to the database table by th
6 min read
How to Export Data to the .CSV File Using SQL Server Stored Procedure? Exporting data from SQL Server to a CSV file is a common task when handling large datasets or sharing data with other applications. SQL Server Management Studio (SSMS) provides a straightforward way to export tables using its Import and Export Wizard. In this article, we will see, the process of exp
3 min read
How to Drop Procedure in SQL In SQL, stored procedures are used to encapsulate complex logic and queries. However, there may come a time when we need to remove or delete a stored procedure from a database. In this article, we will cover the various methods for dropping a stored procedure in SQL along with examples and explanati
3 min read
How to Use Stored Procedure in SQLite? SQLite is a popular, lightweight, self-contained, serverless, and open-source relational database management system (RDBMS) that is widely used in various applications. SQLite does not directly support stored procedures like other database management systems (DBMS) such as MySQL or PostgreSQL. To ac
4 min read