Difference between Stored Procedure and Function

The difference between Stored Procedure and Function is one of the most common interview question. In this article you will learn the basic differences between Stored Procedure and Function.
 
Stored Procedure
  • Stored Procedure may or not return values.
  • Procedures Can have select statements as well as DML statements such as insert, update, delete and so on.
  • Procedures can have both input and output parameters.
  • For exception handling we can use try catch blocks.
  • Can use transactions within Stored Procedures.
  • Procedures Can use both table variables as well as temporary table in it.
  • Stored Procedures can call functions.
  • Procedures can't be called from Select/Where/Having and so on statements. Execute/Exec statement can be used to call/execute Stored Procedure.
  • Procedures can't be used in Join clause.
Function
  • Function must return a value.
  • Will allow only Select statements, it will not allow us to use DML statements.
  • It will allow only input parameters, doesn't support output parameters.
  • It will not allow us to use try-catch blocks.
  • Transactions are not allowed within functions.
  • We can use only table variables, it will not allow using temporary tables.
  • Stored Procedures can't be called from a function.
  • Functions can be called from a select statement.
  • A UDF can be used in join clause as a result set.
Please give your valuable suggestions and feedback.