DIFFERENCE BTW SQL STORED PROCEDURE AND SQL FUNCTION


Below are few differences between Stored Procedure and Function:


1) Stored procedures are compiled for the first time and compiled format is saved and executes compiled code whenever it is called. But the function is compiled and executed every time it is called.

2) Function must return a value but in the stored procedure it is optional.

3) Function takes one input parameter it is mandatory but the stored procedure may take 0 to n input parameters.

4) Functions can be called from select statement, but stored procedures cannot be called from a select statement.

5) We can build logic in functions and we can even break complex logic into methods.

6) We can use try catch statements in stored procedures but in functions, we cannot use.

7) We cannot use insert, delete, update and create statements in functions but in stored procedures, we can use those statements.

8 ) Functions can have only input parameters but the stored procedures can have input and output parameters



Comments

Post a Comment