Aug 4, 2016

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