Can anyone explain what is the exact difference between stored procedures and user defined functions, and in which context each is useful?
Basic DifferenceFunction must return a value but in Stored Procedure it is optional( Procedure can return zero or n values). Functions can have only input parameters for it whereas Procedures can have input/output parameters .
A function would return the returning value/control to the code or calling function. The procedures perform certain tasks in a particular order on the basis of the given inputs. A procedure, on the other hand, would return the control, but would not return any value to the calling function or the code.
A procedure is compiled once and can be called multiple times without being compiled. A function returns a value and control to calling function or code. A procedure returns the control but not any value to calling function or code. A procedure has support for try-catch blocks.
User defined stored procedures are created by database developers or database administrators. These SPs contains one more more SQL statements to select, update, or delete records from database tables. User defined stored procedure can take input parameters and return output parameters.
This is what i always keep in mind :)
Source http://www.codeproject.com/Tips/286539/Difference-between-stored-procedure-and-function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With