Friday, October 16, 2015

SQL: Stored Procedure vs Function - Difference

Following are the difference between sql stored procedures and sql functions

Stored Procedure Functions
Can return 0 or multiple values Function must return a value
SP can call functions Functions can not call SPs
Allow SELECT + DML(INSERT/UPDATE/DELETE) Allow SELECT operation only
Cant not be used in SELECT statements Can be used in SELECT statements
Cant not be used in WHERE/HAVING clause  Can be used in WHERE/HAVING clause
SPs can have INPUT and/or OUTPUT parameters Functions can have input parameters only
This is a precompiled set of statements, hence Compile statements everytime.
Transactions can be created in SPs Transactions can not be created
Allow TRY CATCH blocks Does not allow exception handling

No comments:

Post a Comment