11
Reply

Difference between Stored Procedure and Function

Kalai

Kalai

10y
2.8k
0
Reply

    1) Procedure can return zero or n values whereas function can return one value which is mandatory. 2) Procedures can have input, output parameters for it whereas functions can have only input parameters. 3) Procedure allows select as well as DML statement in it whereas function allows only select statement in it. 4) Functions can be called from procedure whereas procedures cannot be called from function. 5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function. 6) We can go for transaction management in procedure whereas we can't go in function. 7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.

    1.Procedure can have Input Parameter and Output Parameter. Function only have Input Parameter. 2.For Stored Procedure Return type is not must. For function return type is must. 3.Stored Procedure Can have Try....Catch Function cannot have Try....Catch 4.Functions can be called from Procedure whereas Procedures cannot be called from Function

    1- store procedure have input and output parameter, but FUNCITON: have only input parameter. 2-store procedure can do DML process, but FUNCTION can not do that. 3-store procedure return multiple value but FUNCTION return only one value. 4-In store procedure you can call FUNCTIONS but in Function you can't call store procedure.

    Functions can have only input parameters for it whereas Procedures can have input/output parameters .Procedures can have input, output parameters for it whereas functions can have only input parameters.

    http://www.c-sharpcorner.com/UploadFile/996353/difference-between-stored-procedure-and-user-defined-functio/http://dotnet-munesh.blogspot.in/2013/12/difference.html

    Stored Procedure. 1)In sp we can do all dml operations ,in function only select operation is possible 2)In sp we can return more than one value ,in functions only single value is returned. 3)we can call functions inside sp, but we can't call sp inside functions.

    Stored Procedure. 1)In sp we can do all dml operations ,in function only select operation is possible 2)In sp we can return more than one value ,in functions only single value is returned. 3)we can call functions inside sp, but we can't call sp inside functions.

    function is preferred over stored procedure when some of the recurring functionality you want to implement inside database ( within database objects)where as stored procedure is preferred when want to implement recurring functionality between database and client application(e.g. .NET)

    Function 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 .Function takes one input parameter it is mandatory but Stored Procedure may take o to n input parameters..Functions can be called from Procedure whereas Procedures cannot be called from Function.Advance DifferenceProcedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.We can go for Transaction Management in Procedure whereas we can't go in Function.

    1) Procedure can return zero or n values whereas function can return one value which is mandatory.2) Procedures can have input, output parameters for it whereas functions can have only input parameters.3) Procedure allows select as well as DML(INSERT/UPDATE/DELETE) statements in it whereas function allows only select statement in it.4) Functions can be called from procedure whereas procedures cannot be called from function.5) Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.6) We can go for transaction management in procedure whereas we can't go in function.7) Procedures cannot be utilized in a select statement whereas function can be embedded in a select statement.

    1. Procedure can have Input Parameter and Output Parameter.
        Function only have Input Parameter.

    2. Procedure allow INSERT/UPDATE/DELETE Statement.
        Function allow SELECT Statement only.

    3. Procedure can handle Exception Handling.
        Function cannot handle Exception Handling.

    4. Procedure can call a Function.
        Function cannot execute Procedure.