In this blog, I will show step by step how to create a Stored Procedure in SQL Server. explain how its works and why we need to do this. Let’s Go.

I. Microsoft SQL Server

Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications which may run either on the same computer or on another computer across a network.

II. Stored Procedure

stored procedure is a set of Structured Query Language (SQL) statements with an assigned name, which are stored in a relational database management system (RDBMS) as a group, so it can be reused and shared by multiple programs.

A stored procedure is a subroutine available to applications that access a relational database management system. Such procedures are stored in the database data dictionary. Uses for stored procedures include data-validation or access-control mechanisms.

To download MS SQL Server, click Here

III. Requirements

  • Microsoft SQL Server

Download and Install SQL Server Management Studio to proceed this tutorial.

IV. Connect SQL Server

First connect the server, I’ll use my local DB and use windows Authentication. then Connect.

This is the view after connect is suceed.

Click Databases to open the list of databases. And now I use the old sample which is the create previous tutorial/blog about: How to create databases and tables in SQL

This is the sample table inside the testDB database. there is users table and user_genter table.



V. Create Store Procedure

Please follow the steps. TestDB -> Programmability -> Stored Procedures.

Right click the Stored Procedures and click the Stored Procedures…

this is the default script after clicking.

  1. this is the name of the strode procedure and you need to replace it whatever you like it. but for me I named it SP_getUsers.
  2. this is the parameter, incase if you need parameter in your query, but in this case we don’t need it. so I remove that.
  3. This is the important part of the script. the query statement.
  4. the work “Create” replace “Alter” After created.

This is what look like.

And you can refresh and see the created Store Procedures

Related Topics

5 Replies to “Create Stored Procedure in SQL”

  1. I抎 need to check with you here. Which isn’t one thing I normally do! I take pleasure in studying a publish that can make people think. Additionally, thanks for permitting me to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *