Difference between Function and Stored Procedure?

Answer Posted / mohammad sajid

Although both functions and sp's are prcomiled sql
statements there exists some differences between them.

1. Functions must return a value(scalar,inline table or
multi statement table) whereas stored proc may or may not
retun a value.
2.Functions can return a table whereas stored procs can
create a table but can't return table.
3. Stored procs can be called independently using exec
keyword whereas function are called using select statements.
4. Stored procs can be used to change server configuration
(in terms of security-i.e. setting granular permissions of
user rights) whereas function can't be used for this
5. XML and output parameters can't be passed to functions
whereas it can be with sp's.
6.transaction related statement can be handled in sp
whereas it can't be in function.
7. stored procedures can call a funtion or another sstored
proc similarly a function can call another function and a
stored proc.The catch with function is that no user defined
stored proc can be called.Only extended/system defined
procs can be called.

Hope this will be helpful and if there's any correction let
me know.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is nonclustered index with included columns ?

554


What are the two modes of authentication in sql server?

526


While migrating Microsoft SQL Server 2008 database to SQL Azure, what can be done to ensure the database connectivity does not degrade?

89


What is postgresql server?

516


How to find Duplicate Records In table?

587






what exactly sql injuction.how to overcome.....

2044


What is it’s similarity with sql server?

143


Can we update data in a view?

605


How connect excel to sql server?

514


What happens if null values are involved in datetime operations?

539


What is the difference between update lock and exclusive lock?

498


Explain transaction server isolation?

553


can we have a nested transaction? : Sql server database administration

510


What is meant by datasource?

521


What Are the Main Features of SQL Azure?

95