Function vs. Stored Procedure in SQL Server

SQL

I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I should use a function or a stored procedure. They look same to me, maybe because I am kinda newbie about that.

Can some one tell me why?


If you want to unleash your potential in this competitive field, please visit the SQL course page for more information, where you can find the SQL tutorials and SQL frequently asked interview questions and answers as well.

1
Answers

Replies

As, we all know that we can perform the same task by both the Functions and Stored Procedure as well so what to use and when to use it all depend on our requirement.


There are various differences between Functions and Stored Procedure in SQL Server are given below:


 


 


As, you would like to know about when you can prefer function or stored procedure so there are few points given below:


Let suppose if our requirement is something like


If there is no need to use any DML statements
If there is no need to perform any transactions.
If you are required to take only input parameters.
No Exception Handling is required.
If there is a need to return a value.


In all the above cases, we can prefer FUNCTIONS.


Let suppose if our requirement is something like


If there is need to use both SELECT and DML statements
If there is a need to perform any transactions.
If you are required to take both input and output parameters.
Exception Handling is required.
If there is no need to return a value.


In all the above cases, we can prefer Stored Procedure.

 
 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
WhatsApp
To Top