Wednesday, December 10, 2014

Differences between and Stored Procedures and Functions

User Defined function                                              Stored Procedure
----------------------------------------------------------------------------------------------------------
Functions must return a value.                                Stored procedure may or not return values.

Functions Will allow only Select                             Procedures Can have select statements
statement,  will not allow us to                                 as well as DML statements insert,
use DML statements.                                                       update, delete.
                                                                                 
Functions will allow only input                                Procedures can have both input
parameters,doesn’t support    and output parameters.
output parameters.                      

Functions will not allow us to use                            For exception handling we can use
try-catch blocks.                                                                   try catch blocks.

Transactions are not allowed within Can use transactions within Stored
functions.                                                                              procedures.

We can use only table variables,                            Can use both table variables aswell as
it will not allow using temporary tables.                   temporary table in it.

Stored procedures can’t be called from                    Stored Procedures can call functions.
function.

Functions can be called from Procedures can’t be called from
select statement.                                                             Select/Where/Having etc statements.
                                                                                              Execute/Execstatement can be used to                                                                                                       call/execute stored procedure.

UDF can be used in join clause as a result set. Procedures can’t be used in Join clause


Thanks
srinivas

No comments: