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 ...
随机推荐
- Android 实用开源控件
图片放大缩小: PinchImageView 体验最好的图片手势控件,不同分辨率无缝切换,可与ViewPager结合使用. GestureViews 带有手势控制的ImageView和FrameLay ...
- [Java] java.util.Arrays 中使用的 sort 采用的算法 (转)
http://book.douban.com/annotation/15154366/Q: java.util.Arrays 中使用的 sort 采用的是什么算法? A: java中Arrays. ...
- unix network programming volume1 sorce code build and get(UNIX網絡編程卷1第三版)
source code下载地址:unpv13e.tar.gz下载 (也有放一份在google cloud storage) compile 1. ./configure 2. cd lib make ...
- (转载)zeromq使用注意点滴
zeromq使用注意点滴 1.关于介绍zeromq的就不说了,可以自己去看官方guide很详细 2.主要说下在使用过程中需要注意的地方 1)使用如果使用c++的接口的时候,在你自己的类中或者apach ...
- JavaScript:词法结构
1.字符集JavaScript程序是用Unicode字符集编写的. 1.1 区分大小写 JavaScript是区分大小写的语言.也就是说,关键字.变量.函数名和所有标识符(identifier)都必须 ...
- django1.9 创建数据表
1.在setting.py 中注册app: 2.编写models.py 文件创建表结构: (生成的表默认是: app名称_定义的表面 ) 3.执行命令: python manage.py check ...
- ubuntu上安装Eclipse时遇到的一个错误
A Java Runtime Environment (JRE) or Java Development Kit (JDK)must be available in order to run Ecli ...
- js 页码分页的前端写法
<script type="text/javascript"> var curPage = 1;//当前页码 var total;//总页数 $(function () ...
- oracle initialization or shutdown in progress问题解决步骤
今天像往常一样打开电脑,启动plsql工具连接数据库,但是尽然连接不了,报了“oracle initialization or shutdown in progress”的提示信息,从操作系统 ...
- Expect 初学
expect可以帮助脚本完成自动化.今天就用二种实例来介绍2种写法. 安装 yum -y install expect 一.直接用/usr/bin/expect 这种就不方便调用linux下的环境变量 ...