Wednesday, 5 April 2017

What are the major difference's between Stored Procedure and Functions?

Stored Procedures
Functions
Stored procedure is a set of pre-Compiled sql statements, which will get executed for 1 st time and stored plan in the  Execution plan.
Function is a reusable piece of code, which is used to execute same set of statements. And will return a value.
Stored procedure will support exception handling such we can use try catch blocks.
Functions  will  not  support exception handling we can not use try catch blocks.
We can call a function in Stored procedures.
We cannot  call store procedures in functions.
Stored procedures can contain zero or N parameters.
Functions must contain at least one parameter.
Stored procedure always returns INTEGER as data type.
Function will return any data Type .
We can execute stored procedures’ by using EXEC command
We can execute Functions by using SELECT command
Sp’s will accept both input parameters and out put parameters. We can have up to 21,000 input parameters.
Functions will accept only in put parameters and but not output parameters. We can have up to 1,023 input parameters

We can perform will DML operations like INSERT,UPDATE,DELETE with sp’s
We cannot perform DML operations.
We can call one sp’s in another stored procedure.
We can call one function  another function.
Stored Procedure may or not return values.
Function must return a value.
Can use transactions within Stored Procedures.
Transactions are not allowed within functions.
Can use both table variables as well as temporary table in it.
We can use only table variables, it will not allow using temporary tables.
Procedures can’t be used in Join clause
A UDF can be used in join clause as a result set.
Dynamic sql will support in stored procedures
Dynamic sql will not  support in funcions
Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section 
whereas Function can be.

No comments:

Post a Comment

SQL_DBA- Ip Address Ping

Start-Transcript - path C:/Script/PingLog.txt -Append   Ping.exe -t spiceworks.com | ForEach { "{0} - {1}" -f (Get-Date), $_ } ...