Difference between function and stored procedure in SQL Server


Some basic difference between stored procedure and function is described below.

The main difference between stored procedure and function is Function must returns a value while stored procedure can or not this is optional. Function can have input parameter only while stored procedure can have both input/output parameters. Function can be called from stored procedures but stored procedures can’t call from function.

Function

Stored Procedure
Function must returns a value

In stored procedure it is optional
Function can have input parameter only
Stored procedure can have both input and output parameter s
Function can be called from procedure

Procedure can‘t be called from function
Function allows only select statement
Procedure allows DML statement(SELECT, INSERT, UPDATE, DELETE)
Function can use in SQL statement like WHERE/HAVING/SELECT

Procedure can’t be use in SQL statement like WHERE/HAVING/SELECT
Function can return table and can be treated as another row set. This can be use in joins with other tables.


Transaction can’t be implement

Transaction can be implement in stored procedure



No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...