Thursday, June 19, 2014

Difference between Store procedure and user defined function in SQL

Difference between Store procedure and function
Store procedure
Function
Store procedure is a pre-compile object which is which are compile for first time and its compile format is saved which executes (compile code) whenever it is called.
Function is compiled every time when it is called.
Procedure allows select as well as DML (INSERT/UPDATE/EDIT) statement.
Function allows only SELECT Statement.
Procedures cannot utilize in SELECT Statement
Function can be embedded in SELECT Statement.
Store procedure cannot be used in SQL statement anywhere in the WHERE/HAVING/SELECT Section.
Function Can be
We can go for transaction Management in Procedure.
We cannot go for transaction in Function
Procedure can return 0 or n values (It is optional).
Function must return a value
Procedure can have input output parameters.
Function can have only input parameters.
Function can be called in procedure.
A store procedure cannot be called in function.
Exception can be handled through catch and try block in procedure.
Exception cannot be handled in function.
Store procedure can be called using execute store procedure name
Function can be called using select statement.

Another point are-
·         Function that returns table can be treated as another row set. That can be used in joins and other table.

·         Inline function  can be tough  of as view that take parameters  and can be used other  row set operations

No comments:

Post a Comment