ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Muhammed Effat Ahmed Afifi , Project Leader [Microsoft Business Unit] , Wipro Arabia Limited
تاريخ النشر: 2013/10/11
Andrew Francis
من قبل 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
من قبل 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.

 

 

المزيد من الأسئلة المماثلة