1. Functions are compiled and executed at run time.
Stored procedures are stored in parsed and compiled format in the database.
2. Functions cannot affect the state of the database which means we cannot perform insert,delete,update and create operations on the database.
Stored Procedures can affect the state of the database by using insert,delete,update and create operations.
3 Functions are basically used to compute values. We passes some parameters to functions as input and then it performs some operations on the parameter and return output.
Stored procedures are basically used to process the task.
4.Function can not change server environment and our operating system environment.
Stored procedures can change server environment and our operating system environment.
5.Functions can not be invoked from SQL Statements. Execute. SELECT
operating system can be invoked from SQL Statements. Execute. SELECT
6.Functions can run an executable file from SQL SELECT or an action query.
operating system use Execute or Exec to run
--------------------------------------------------------------------
Thanks
Alok Kumar Sharma
Stored procedures are stored in parsed and compiled format in the database.
2. Functions cannot affect the state of the database which means we cannot perform insert,delete,update and create operations on the database.
Stored Procedures can affect the state of the database by using insert,delete,update and create operations.
3 Functions are basically used to compute values. We passes some parameters to functions as input and then it performs some operations on the parameter and return output.
Stored procedures are basically used to process the task.
4.Function can not change server environment and our operating system environment.
Stored procedures can change server environment and our operating system environment.
5.Functions can not be invoked from SQL Statements. Execute. SELECT
operating system can be invoked from SQL Statements. Execute. SELECT
6.Functions can run an executable file from SQL SELECT or an action query.
operating system use Execute or Exec to run
--------------------------------------------------------------------
Features
|
Procedures
|
Functions
|
|
Parameters
|
Supports in, out, in & out
|
Only supports in
|
|
Temp Object
|
Accessible – You can use the temp tables inside the procedure
|
Not supported
|
|
Create as Temp
|
Accepted –
Create Proc #MyProc..
|
Not supported
|
|
Select Result
|
Supported
|
Not supported
|
|
Return
|
Return integer value
|
Returns any type of value
|
|
On DML Quires
|
Not allowed
|
You can embed the function on query
|
|
Calling SPs
|
Allowed
|
Not Allowed
|
|
Calling Another Functions
|
Allowed
|
Allowed
|
|
Insert/Update/Delete
|
Allowed
|
Not Allowed
Or
Only allowed against the table variables
|
|
Recursive Operation
|
Allowed
|
Allowed
|
|
Versioning (grouped)
|
Allowed
|
Not Allowed
|
|
Schema Binding
|
Not Allowed
|
Allowed
|
|
Creating Objects
|
Allowed
|
Not Allowed
|
|
EXEC
|
Allowed
|
Not Allowed
|
|
SP_EXECUTESQL
Dynamic SQL
|
Allowed
|
Not Allowed
|
|
GETDATE() or other non-deterministic functions
|
Allowed
|
Not Allowed
|
|
SET OPTION
|
Not Allowed
|
Allowed
|
|
Setting Permission
Grant/Deny
|
Yes
|
No for scalar functions.
Yes for Table Values/Inline Functions
|
Thanks
Alok Kumar Sharma
Helpful to get difference between Function and store procedure
ReplyDeletethis will be really helpful sir thanx a lot
ReplyDelete