Before you decide in using Function or Stored Procedure, you must know that a function cannot used SQL statement like INSERT, UPDATE and DELETE while a stored procedure can. A function also does not support error handling but a stored procedure support error handling (you must include the error handling). Below are more on differences between both:
Related Articles
- Function can be used in a select statement but a stored procedure can't.
- Functions are mostly used for computations while Stored Procedures are used for business logic.
- Function must return a value while Stored Procedure are optional.
- Function accept only input parameters while Stored Procedures can accept input and output parameters.
- GETDATE() or other non-deterministic functions is not allow in Function but are allow in Stored Procedures.
- StoredProcedure can use Temporary Tables while Function can't.
- Function can not Execute Dynamic SQL while a Stored Procedure can.