Using Stored Procedures In MSSQL
Today, I want to talk about using stored procedures in MsSql. First let me explain why we need Stored procedures. Stored procedure means, SQL statements that are kept in the database and compiled in the first run and do not need to be recompiled later. We will do it by procedures.
Procedures has a lot of advantages. Main one is it’s working very fast. Because it only compiles once and no need to compile again. And you can also use if else while operations in the stored procedures.
Let start creating a simple procedure.
1 2 3 4 |
CREATE PROC GetSpesificUser @UserName nvarchar(30) AS SELECT * FROM Users WHERE Name=@UserName |
We define a procedure which has a parameter. This parameter helps us to get the named users. And we will run this procedure by the following code.
1 |
EXEC GetSpesificUser 'Ali' |
That’s all so easy. You can create more complex procedures which has input parameters and output parameters. Procedures are especially very useful for your reporting requirements. If you are looking for triggers in MsSql, have a look at Triggers In MsSql
If you have question do not forget to write from the chat button next to it or from the comment.
2 Responses
[…] If you are searching for Stored Procedures, have a look at this post: Stored Procedures In MsSql […]
[…] Thats all for subquerying in Oracle. If you have interested about MS SqlServer you can have a look at my other post Using Stored Procedures In MSSQL […]