Difference between Stored Procedure and Function in SQL Server
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
Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
Functions can have only input parameters for it whereas Procedures can have input/output parameters .
Functions can be called from Procedure whereas Procedures cannot be called from Function.
Advance Difference
Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.
Procedures can not be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.
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.
Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.
Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
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的更多相关文章
- SQL Stored Procedure and Function
Anything can be programmable with defined syntax and common lib. )) -- Add the parameters for the st ...
- 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 ...
- [EF] - Entity Framework 6处理User Defined Function(UDF SQL Server)
随着EF5的发布,新增了对数据库(SQL Server) UDF的支持,具体可以看以下的连接:https://msdn.microsoft.com/en-us/data/hh859577.aspx,新 ...
- Part 8 Coalesce function in sql server
- SQL Server ->> EXECUTE AS LOGIN/USER和Revert表达式
EXECUTE AS LOGIN/USER和Revert表达式都是从SQL Server 2005就有.Revert的作用是用于切换当前过程的执行上下文返回上一个EXECUTE AS 语句发生之前的安 ...
- Northwind数据库不能在SQL Server 2012上创建
附加mdf文件不出意料会提示数据库格式无法兼容,试着通过脚本来创建,会有以下错误提示: Could not find stored procedure 'sp_dboption'. 原因是SQL Se ...
- Microsoft SQL Server Trace Flags
Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...
- Sql Server问题集锦
Sql数据库默认实例和命名实例的区别: 1.服务中服务名称的区别: 默认实例:MSSQLSERVER; 命名实例:实列名为:benet,在服务中的名称是:MSSQL$BENET; 注:如果你有多个 ...
- 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 ...
随机推荐
- eclipse svn proxy
C:\Users\userName\AppData\Roaming\Subversion下的servers文件, 将#http-proxy-host和#http-proxy-port这两行前面的#号去 ...
- js 过滤敏感词
<html> <head> <title>Bad Words Example</title> <script type=" ...
- 《DON'T MAKE ME THINK》/《点石成金访客至上的网页设计秘笈》 读书笔记
1.web页面要尽可能简单,让用户不用思考就能知道页面的功能,如果要进行一些崭新的.开拓性的或者非常复杂的页面设计时, 此时要利用页面元素的外观.精心选择的名称.页面布局以及少量仔细斟酌过的文字,使页 ...
- ACM: HDU 1285 确定比赛名次 - 拓扑排序
HDU 1285 确定比赛名次 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 【CodeVS】P1041 car的旅行路线
题目描述 Description 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于一个矩形的四个顶点上,同一个城市中两个机场之间有一条笔直的高速铁路,第I ...
- 属性字符串的replaceCharactersInRange方法
一,实验: 1> 让 range 的 length 参数为0,以下代码输出属性字符串的结果为12354 NSMutableAttributedString *attrStr = [[NSMuta ...
- linux下搭建svn代码库
1.安装svn客户端 2.创建svn代码库 1.安装svn客户端 1.1.使用命令安装 1)CentOS $ yum install subversion 2)ubuntu sudo apt-get ...
- ArcGIS几种数据格式
ArcGIS几种数据格式 ArcInfo常用以下格式的数据:shp.Coverage..Raster CAD和Geodatabase.各种数据的组织形式不一样,其中shp.Coverage.Raste ...
- 在eclipse程序中设置的断点上有一个斜杠,正常启动debug不能够跳转到debug页面,怎么解决
在run菜单里面,把skip all breakpoints 选项勾去即可,这个选项可能是你无意间选上的.
- MVVM deep dive
You can get a different instance each time by passing a different key to the GetInstance method. How ...