When to use stored procedure and when to use function?
When to use stored procedure and when to use function?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Jun 1, 2015, 4:05 AM
2) Procedures can have input, output parameters for it whereas functions can have only input parameters.
3) Procedure allows select as well as DML(INSERT/UPDATE/DELETE) statements in it whereas function allows 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 cannot be utilized in a select statement whereas function can be embedded in a select statement.
Syed ShanuPosted May 31, 2015, 8:13 PM
Jagdev MishraPosted May 29, 2015, 7:20 AM
Upendra Pratap ShahiPosted May 29, 2015, 7:19 AM
Nilesh JadavPosted May 29, 2015, 7:11 AM
1) It protect your table data from intruders.
2) Using Store Procedures you are separating your database from the coding
part, and it is good thing. From that any one can understand the flow of your application.
3) It also used for making fewer calls to the database. Suppose you want to fire 4 sql query. If you are using Store Procedure you can do it by one sql statement. Hence not much disturbance to the Database.
1) It Can be used with Select statement
2) It will not return output parameter but returns Table variables
3) You can join UDF
4) It Cannot be used to change server configuration
5) It Cannot be used with XML FOR clause
6) It Cannot have transaction within function
Syed ShanuPosted May 29, 2015, 4:52 AM
Khargesh RajputPosted May 29, 2015, 4:32 AM