Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all ,

Can anyone tell me whats the difference between stored procedure & functions?

Why do we go for stored procedures when we have class libraries?

Thanks in advance

Naveen...
Posted
Updated 5-Jul-10 4:29am
v2

SQL
Hi,

1>Procedure can return zero or n values whereas function can return one value which is mandatory.

2>Procedures can have input,output parameters for it whereas functions can have only input parameters.

3>Procedure allow select as well as DML statement in it whereas function allow only select statement in it.

4>Functions can be called from procedure whereas procedures cannot be called from function.

5>Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.

6>We can go for transaction management in procedure whereas we can't go in function.

7>Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
 
Share this answer
 
Thank you Puranjay34

that was a good explanation.where do you get these good simple definitions.really good to understand for beginners.

Could you tell me "Why do we go for stored procedures when we have class libraries?"

Regards

Naveen...
 
Share this answer
 
If you are taking about SQL server functions, then for a difference, see here.
 
Share this answer
 
No abhinav ,:confused:

i dint mean sql functions.
This question was asked in an interview .
Watz the diff between stored procedure & functions in
Visual studio,(VB.net or c #) ?

Thanks in advance

Naveen.... :rolleyes:
 
Share this answer
 
Comments
Christian Graus 31-Aug-10 6:31am    
Your interviewer was a retard. Stored procedures only exist in SQL. Also, don't push 'answer' to comment or ask questions, and don't make the mistake of thinking that getting us to answer an interview question will get you a job, no one answer will save the day or lose you a job, if you're generally competent.
nav234 31-Aug-10 8:55am    
Yeah your right Mr.Christian ,i thought like if i get answers now for those interview questions ,it will be useful for me in later (or next) interviews.or i could help my friends also if they need.that's why iam posting all those interview questions in this website.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900