Differences between Functions and Stored Procedures
in SQL Server
Stored Procedure:
·
Stored Procedures are a batch of SQL statements
that can be executed in a couple of ways.
·
Stored Procedure is a Set precompiled SQL
statements that used to perform a special Task
·
Stored procedure is a group of SQL statements that
has been created and stored in the database.
·
Store Procedure use to retrieve data, modify
data, and delete data in Database table.
Function:
·
User-defined function is a Transact-SQL or common
language run time (CLR) routine that accepts parameters, performs an action,
such as a complex calculation, and returns the result of that action as a
value. The return value can either be a scalar (single) value or a table.
·
Function is a database object in SQL Server.
Basically it is a set of SQL statements that accepts only input parameters,
perform actions and return the result. Function can return only single value or
a table.
·
Microsoft has introduced the concept of
User-Defined Functions that allow you to define your own T-SQL functions that can
accept zero or more parameters and return a single scalar data value or a table
data type.
Difference
between them (Functions and Stored Procedures)
Stored Procedure
|
Function
|
|
Function always return value
|
|
Normally functions will be used for computing value
|
|
Function can be called from select/where/having
clause
|
|
Function cannot run independently
|
|
Function cannot be used in the function. But we can
use raise error function.
|
|
Function cannot call the stored procedures.
|
|
Function can have only input parameters.
|
|
Function can do only select operation.
|
|
Function cannot have the transaction statements.
|
|
Function cannot use the ntext, image and timestamp
data types as return type.
|
|
Function can create, update and delete the table
variable. It can return table variable.
|
|
Function cannot execute the sp_executesql statement.
|
No comments:
Post a Comment