Difference between Stored Procedures and Functions

Stored Procedure (SP) Function (User Defined Function - UDF)
SPs are pre-compile objects which are compiled for first time and its compiled format is saved which executes (compiled code) whenever it is called Functions are compiled and executed every time when it is called
SP can return zero, single or multiple values Function should return atleast one value
We can use Transactions in SP Cannot use transactions in UDF
SPs can use SELECT, UPDATE, INSERT, DELETE, DROP statements Functions are computed values and only SELECT statement is valid
SPs cannot be utilised in SELECT statements Functions can be embedded in SELECT statement
SP can have input and output parameter UDFs can have only input parameters
SPs can can execute with or without parameters UDFs needs at least one input parameter. Without parameter UDFs can be created but it would be a insignificant one
We call function from SP We cannot call SP from an UDF
Exception handlers like TRY-CATCH blocks can be used in SP Cannot use Exception handlers can be used in UDF

No comments:

Post a Comment