Saturday, January 18, 2014

Difference between Stored Procedure and Function in SQL Server?

Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes (compiled code) whenever it is called. But Function is compiled and executed every time when it is called.

1. Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.

2.Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.

3. Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.

4. Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.

No comments:

Post a Comment

Abstract Factory Vs Factory Method

Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes ...