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 master database? : SQL Server Architecture

535


What is exporting utility?

544


What is the impact on other user sessions when creating indexes?

542


How to copy data from one table to another table?

544


How to create nested stored procedure?

541






What is a transact-sql statement?

537


What are the restrictions applicable while creating views? : SQL Server Architecture

586


What is policy management?

581


Explain the relational database management system (rdbms)?

526


What is difference between line feed ( ) and carriage return ( )?

523


How do I repair damaged sql server mdf file database? In previous day my mdf file has got damage due to unknown reasons then I used dbcc chekcdb command but it failed, MDF file is important for me, I don’ know that how to get back mdf file data. Please anyone suggest me?

1298


What are the types of processing and explain each? : sql server analysis services, ssas

738


What are trace files?

535


Suppose i have a table that contains 5 columns like col1,col2...colm5.I want to import only two column through BCP utility.How to do same through BCP in sybase.

1966


What happens if we shrink log file in sql server?

519