Introduction:
In this article i will explain the difference between Stored procedures and User Defined Functions
(UDF's) in SQL Server.
Stored
Procedure:
A stored procedure is a pre-compiled group of Transact-SQL statements .We can say a stored procedure is
a prepared SQL code that we save so that we can reuse the code over and over
again. If a repetitive T-SQL task has to be executed within an application, then the best way for it is to create stored procedure.
You can also pass parameters to the stored procedure, so depending on what the need is the stored procedure can act accordingly based on the parameter values that were passed to it.
User Defined Function (UDF):
User Defined Function in SQL
Server is a Transact-SQL or
common language runtime (CLR) routine that takes parameters,
performs an action, and returns the result of that action as a value. The
return value can either be a scalar (single) value or a table.
Two type of functions are there
in SQL i.e. Scalar valued Functions & Table Valued.