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.
|
Wednesday, 5 April 2017
What are the major difference's between Stored Procedure and Functions?
Subscribe to:
Post Comments (Atom)
SQLDBA - Get Space Used by Tables and Indexes in SQL Server
Get Space Used by Tables and Indexes in SQL Server Databases can consume significant amounts of storage, so it’s important to understand ho...
-
Have your SQL queries been eating up CPU like it's a buffet? Then it’s time to talk about the most underrated setting in SQL Server: ...
-
Issue: The SQL Server service for our cluster could not be brought online during a recent failover due to registry not found error(s). How...
-
-- Health and status of WSFC cluster. These two queries work only if the WSFC has quorum SELECT * FROM sys.dm_hadr_cluster SELECT * FROM sy...
No comments:
Post a Comment