- How to create a Stored Procedure
- How to modify a Stored Procedure
- How to delete a Stored Procedure
- Grant Permissions on a Stored Procedure
- How to return data from a Procedure
- How to get Stored Procedure’s data from a C# application
- Dependencies of a Stored Procedure
Stored Procedure Benefits
A stored procedure provides control and condition handling statements, in addition to multiple input and output parameters and local variables, that make SQL a computationally complete programming language. Applications based on stored procedure provide the following benefits over equivalent embedded SQL applications:
- Better performance because of greatly reduced network traffic between the client and server.
- Better application maintenance because business rules are encapsulated enforced on the server.
- Better transaction control.
- Better application security by restricting user access to procedures rather than requiring them to access data table directly.
How to create a Stored Procedure
Here, I will create a simple stored procedure which will retrieve data based on the given parameter value.
In SQL Management Studio expand your database under which you want to create the procedure. There will be a directory name “
Programmability”.
Expand the mentioned directory and create a new stored procedure right clicking on the “Stored Procedure.” Select the “
Specify Values for Template Parameters” option from “
Query” menu.
In the opened dialog box specify the values as in the following:
Now the template will be like the following:
We have to replace the SQL SELECT statement with our own query. I have used a simple SELECT query here.
- SELECT*FROMdbo.testWHEREID=@IDANDEmail=@Email;
We can test our query syntax from “Parse” option under “Query” menu. To create this procedure click the “
Execute” option. After refreshing the “Stored Procedure” directory the procedure will be visible here with the given name.
So we have successfully created our first stored procedure using SQL Management Studio. I’ll discuss the other topics sequentially in my next article.