Differences Between Stored Procedures and Functions in SQL Server

Hello to everyone,

In this article, I will talk about the difference between stored procedures and functions in SQL Server.

Stored procedures are sql statements that are stored by the database and do not need to be recompiled after the first compilation.

Functions are sql codes that can return any type of value.

The differences between them are below.

  1. Functions always return a value (Number, string expression, table, etc.) Stored procedures may or may not return a value.
  2. Functions have only input parameters, but stored procedures have both input and output parameters.
  3. Functions can be run by stored procedures, but stored procedures cannot be run inside functions.
  4. Functions can only be used with a Select statement. CRUD operations are not performed with functions. You can do all CRUD (Create/Read/Update/Delete) operations with stored procedures.
  5. You cannot use the try-catch construct in functions, but you can use it with stored procedures.
  6. Functions do not support transaction structures, but stored procedures do.
  7. Functions do not support the PRINT statement. PRINT statement can be used in stored procedures.
  8. The result set returned by the function can be used in JOIN operations. Not used with stored procedures.
  9. You can use TABLE variable inside the function. Functions The use of TEMPORARY TABLE is not allowed. TABLE variable and TEMPORARY TABLE can be used in stored procedure.

Good luck to everyone in business and life.

33 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!