Difference between stored procedure and function

Stored Procedure vs Function
  1. Stored procedure cannot be executed using SQL Select command whereas Function (UDF) can be executed using SQL Select command. Stored Procedure can be executed using execute command i.e EXEC or EXECUTE 
  2. Stored Procedure can return zero to n values whereas Function can return one value that is mandatory
  3. Stored Procedure can have input and output parameters whereas Function can have only input parameters.
  4. Stored Procedure can call functions whereas Function cannot call stored procedures.
  5. Stored Procedure exception handling can be done by try-catch block whereas Function exception handling cannot be done by try-catch block.
  6. Stored Procedure can't return a table variable although it can create a table while Function returns table variables.
  7. Stored Procedure can change the server environment or your operating system environment, while Function can change the server environment or your operating system environment

No comments:

Popular Posts