Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the major difference between sql function and store procedure?

user-image
Question added by Muhammed Effat Ahmed Afifi , Project Leader [Microsoft Business Unit] , Wipro Arabia Limited
Date Posted: 2013/10/11
Andrew Francis
by Andrew Francis , Senior Software Developer , OMS

  • Procedure can return zero or n values whereas function can return one value which is mandatory.
  • Procedures can have input/output parameters for it whereas functions can have only input parameters.
  • Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
  • Functions can be called from procedure whereas procedures cannot be called from function.
  • Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
  • We can go for transaction management in procedure whereas we can't go in function.
  • Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
  • UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
  • UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
  • Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

Asif ahmed Syed
by Asif ahmed Syed , Lead SharePoint Application Developer , International Center for Sports Security

There are a lot of differences between function and Stored Procedures the basic difference is Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes whenever it is called. But Function is compiled and executed every time when it is called.

 

Function takes one input parameter it is mandatory but Stored Procedure may take o to n input parameters.

 

Procedure allows SELECT as well as INSERT UPDATE DELETE statement in it whereas Function allows only SELECT statement in it.

 

There are so many other differences.

Here are few simple differences between functions and stored procs

enter image description here

Also 

User defined functions have three main categories:

 

Scalar-valued function - returns a scalar value such as an integer or a timestamp. Can be used as column name in queries.

 

Inline function - can have a single SELECT statement.

 

Table-valued function - can contain any number of statements that populate the table variable to be returned. They are useful when a set of rows need to be returned

 

Please let me know for any other information.

 

 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.