27
SQL - Stored Procedure 📦
SQL is the standard language for the Relational Database, for storing, manipulating and retrieving stored data. For basics of SQL (link)
A Stored Procedure is a SQL code that we can save, so the code can be reused again and again.
So, if we have any SQL query which we write over and over again, we can use it as a stored procedure so that we can just call it to execute it.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--bjc-QcNH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6j2wlzz9nq0w9hvy63mr.png)
![](https://res.cloudinary.com/practicaldev/image/fetch/s--njw88bhm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qcs3s7xf0r86s7jae3f.png)
To add Parameters in the procedure, first, we need to alter the procedure for which we can use ALTER procedure statement as follows:
![](https://res.cloudinary.com/practicaldev/image/fetch/s--SPNz-03N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xi67hi2habd6ye7f3o9i.png)
To Execute the above stored procedure, we have to declare a variable for output parameter and specify the parameter as out
![](https://res.cloudinary.com/practicaldev/image/fetch/s--UHmvR7FL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysdwj14a3gj17nkphv0k.png)
Just like this, we can also set multiple parameters by separating each parameter and the data type with a comma
To drop a stored procedure, use the DROP statement as follows:
DROP PROCEDURE usp_proc;
Thank you!! Feel free to comment on any type of feedback or error you have 😄✌
27