Sunday, May 8, 2011

Stored Procedure Vs Function





Stored Procedure
User Defined Function
Stored procedures are basically used to process the task.
Functions are basically used to compute values
Stored procedures are stored in parsed and compiled format in the database
Functions are compiled and executed at run time
SP can’t be used in line
Functions can be used in line with a select statement
Procedure can return zero or n values
function can return one value which is mandatory
Exception can be handled by try-catch block in a procedure
try-catch block cannot be used in a function
We can go for transaction management in procedure
In function we can’t
EXEC command can be used inside a Function
EXEC command can't be used inside a Function
Procedure can modify the state of Database
Function can not
SPROC can be used in an XML FOR clause
UDF cannot be
can have transaction within SP
Cannot have transaction within function
SP can change the server environment or your operating system environment
UDF Can’t
DDL & DML Statements can be used
Can’t be used
Can’t be used within joins
Function can be used in joins