Stored Procedures are pre-compile objects which are compiled for first time and its compiled format is saved which executes (compiled code) whenever it is called. But Function is compiled and executed every time when it is called. For more about stored procedure and function refer the articles Different types of Stored Procedure andDifferent types of Function.

Basic Difference

  1. Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).

  2. Functions can have only input parameters for it whereas Procedures can have input/output parameters .

  3. Functions can be called from Procedure whereas Procedures cannot be called from Function.

Advance Difference

  1. Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.

  2. Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.

  3. Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.

  4. The most important feature of stored procedures over function is to retention and reuse the execution plan while in case of function it will be compiled every time.

  5. Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.

  6. Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

  7. Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.

  8. We can go for Transaction Management in Procedure whereas we can't go in Function.

Summary

In this article I try to explain the difference between Stored Procedure and Function. I hope after reading this article you will be able to understand BASIC as well as ADVANCE difference between Stored Procedure and Functions (UDF). Comments, criticism and suggestions are always welcome.

Difference between Stored Procedure and Function in SQL Server的更多相关文章

  1. SQL Stored Procedure and Function

    Anything can be programmable with defined syntax and common lib. )) -- Add the parameters for the st ...

  2. sql: table,view,function, procedure created MS_Description in sql server

    --添加描述 geovindu --https://msdn.microsoft.com/en-us/library/ms180047.aspx --https://msdn.microsoft.co ...

  3. [EF] - Entity Framework 6处理User Defined Function(UDF SQL Server)

    随着EF5的发布,新增了对数据库(SQL Server) UDF的支持,具体可以看以下的连接:https://msdn.microsoft.com/en-us/data/hh859577.aspx,新 ...

  4. Part 8 Coalesce function in sql server

  5. SQL Server ->> EXECUTE AS LOGIN/USER和Revert表达式

    EXECUTE AS LOGIN/USER和Revert表达式都是从SQL Server 2005就有.Revert的作用是用于切换当前过程的执行上下文返回上一个EXECUTE AS 语句发生之前的安 ...

  6. Northwind数据库不能在SQL Server 2012上创建

    附加mdf文件不出意料会提示数据库格式无法兼容,试着通过脚本来创建,会有以下错误提示: Could not find stored procedure 'sp_dboption'. 原因是SQL Se ...

  7. Microsoft SQL Server Trace Flags

    Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...

  8. Sql Server问题集锦

    Sql数据库默认实例和命名实例的区别: 1.服务中服务名称的区别: 默认实例:MSSQLSERVER; 命名实例:实列名为:benet,在服务中的名称是:MSSQL$BENET;   注:如果你有多个 ...

  9. Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]

    http://sqlserverbuilds.blogspot.jp/   What version of SQL Server do I have? This unofficial build ch ...

随机推荐

  1. iOS学习04C语言数组

    1.一维数组 数组:具有相同类型的成员组成的一组数据 1> 定义 元素:数组中存放的数据成为数组的元素     数组是构造类型,用{...}来给构造类型赋初始值,类型修饰符用来表示元素的类型 类 ...

  2. BZOJ1950 : [Ceoi2006]Link

    显然在最优解中,添加的边都是从$1$出发的. 这个图是一个环套树的结构,对于树的部分,显然叶子节点必须加边. 因此可以自底向上确定树中哪些节点需要加边,同时得到$1$到环上每个点的距离. 对于每个环, ...

  3. BZOJ4380 : [POI2015]Myjnie

    将$c$离散化,设: $f[i][j][k]$为区间$[i,j]$最小值为$k$的最大收益. $g[i][j][k]$为$\max(g[i][j][k..m])$. $h[i][j]$为对于当前DP区 ...

  4. BZOJ1103[POI2007]大都市meg 题解

    题目大意: 有一棵树,最先每条边的权值是1,然后给出n+m-1个操作,操作有两种:1.询问一个点到根的路径上的权值和:2.将一条边的权值改为0. 思路: 用dfs序将树化为序列,在dfs序中我们会保存 ...

  5. ACM:a^b%p-数论-快速幂-快速乘

    a^b Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: Description 求a的b次方,取模mod(1<=a,b ...

  6. Google测试分享-测试经理

    首先大家可以思考下,google的测试经理角色必须具备什么样的能力.据不完全统计,google的测试经理,超过一半之前都做过TE的角色(大家可以想想为啥):对于与被测产品相关的任何使用问题,测试经理都 ...

  7. 使用Canvas绘制图形的基本教程

    原文地址:http://www.cnblogs.com/picaso/archive/2012/11/26/2789077.html HTML5火的正热,最近有个想法也是要用到HTML的相关功能,所以 ...

  8. 2分钟 windows下sublime text 3安装git插件:

    12:35 2015/11/182分钟 windows下sublime text 3安装git插件:推荐博客:http://blog.csdn.net/naola2001/article/detail ...

  9. WinForm上显示gif动画:转

    WinForm上的ProgressBar,老实说,实在是不敢恭维,太死板,太难看了,即使做成实时显示处理进度的,它还是逃离不了“难看”.现 在的web2.0上到处都能看到一个显示正在处理的小圆圈在那转 ...

  10. Radar Installation

    Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...