In this article I will tell about the Stored Procedure which should be used in large projects.
I think it should definitely be used in large-scale projects because the difference of Stored procedures only occurs in projects that require large-scale performance and efficiency.
Stored procedure in general, we can describe as follows: SQL statements which is not needed to compile after first compilation and keeps in the database server. On the other hand, we can say T-SQL statements stored in Database server instead of Application layer.
Stored procedures, as in other programming languages, can be run without parameters. It is also called SP when using in application development. All database operations can be done with Stored procedures.
One of the most beautiful features of using stored procedures is perhaps seperate the programming language codes from the DML (Database manipulation Language) database queries. In addition, once you have written and compiled a SP you can use many times.
In general, I will state the advantages of Stored procedures and why they are used too much as following.
- Stored Procedures are very fast because they are kept in the database server, the reason is that they do not need to compile one more time after compiling one time alone. However, the SQL code that you sent in the Application layer has to be compiled again and again at every transaction. This is a great waste of time for large-scale projects and servers serving more than 1 client.
- Provides excellent savings in network traffic.
- It provides automatic parameterization to SQL statements. Instead of replacing all parameters in the place where SQL statements pass, you can only modify the parameters or rules within the SP. This also fixes the complexity of applications that allows your application to be modular.
- You can use T-SQL commands in addition to programming expressions (if, while, for, etc.) when writing stored procedures.
- Stored procedures are more reliable because only the input and output parameters appear in the application layer. If we think that access to the database server is usually done with the user ID and password, we can say that using SP is an element of trust for our codes.
I have explained the advantages of Stored procedures that came to my mind above. Almost all of the software applications do not use normal sql codes in general.
As I said above, being managed from a single point and using it in more than one place and not being able to see other people easily makes SPs very advantageous.
Especially when we think about Network traffic, sending many lines SQL commands sent by the client to the server instead of sending the name of the Stored Procedure to the server one time it means that Network traffic is very relieved.
There are Four types of Stored Procedures.
- System Stored Procedure : they are in the master database and sp_ prefix is used for these stored procedures. They are used in system-related administrative jobs on the database.
- User based Stored Procedure : These stored procedures are used for our applications. You can delete or change these SP.
- Extended Stored Procedure : Generally, it is compiled like .dll and a type of stored procedure that compiles the Database Server’s functionality. it is added only to the master database.
- CLR Stored Procedure : It is a kind of Stored procedure developed in CLR environment using any language.
Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.
1,930 views last month, 3 views today