Friday, December 14, 2012

What is the difference between sp(stored procedure) and function?

functions and sp(stored procedures) are different from each other in many ways(return type,table variable etc.) .Difference between sp and functions is given below.

Difference between sp and functions:

1:Return Value:

The first difference between sp(stored procedure ) and function  is return value .stored procedures may or may not return a value but functions always returns values.

2:Return type Table variable  :

Stored procedure never have a table variable return type in sql server 2005 but present in sql server 2008 .Function can have a table  return type .In case of inline table valued functions it always returns a table variable.

3:Inline Query:

We can call a function from  within a stored procedure .
We cannot call sp(stored procedure) from within a function. Only functions and extended stored procedures can be executed from within a function.

extended stored procedures:
Extended stored procedures are stored procedures that call functions from DLL files.but they often causes memory leak.

No comments:

Post a Comment