Differences Between Stored Procedure and Function in MS SQL

Many people using ms sql have wondered about the differences between stored procedure and function.

Although they both look alike, they actually have different aspects.

Below are the differences between the stored procedure and the function.

Functions

  • Always returns a value.
  • Only "input" takes parameters.
  • It can be called in the Stored Procedure.
  • You cannot use transactions.
  • You cannot use "try-catch" blocks to catch errors.
  • You can use it in SELECT query.
  • You cannot use INSERT, UPDATE, DELETE inside the function.

Stored Procedure

  • It doesn't always have to return a value.
  • Both "input" and "output" can take parameters.
  • Cannot be called within a function.
  • You can use transactions.
  • You can use "try-catch" blocks to catch errors.
  • You cannot use it in SELECT query.
  • You can use INSERT, UPDATE, DELETE in Stored Procedure.


You May Interest

What are Sparse Columns in SQL Server ?

Deleting Table With Query in MS SQL

How to Restart SQL Server in Single-User Mode ?

Getting List of All Stored Procedures in Database in MS SQL

MS SQL Restoring a Database With a Query