zoukankan      html  css  js  c++  java
  • 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

    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.

  • 相关阅读:
    【LeetCode-位运算】位1的个数
    【LeetCode-数组】调整数组顺序使奇数位于偶数前面
    mySQL数据库中.frm和.myi和.myd和.ibd文件是什么文件?
    安装docker-compose的两种方式
    将第三方jar包 安装到 maven仓库
    limit分页查询
    pom.xml配置指定仓库
    linux常用命令
    正则笔记
    使用conda创建虚拟环境
  • 原文地址:https://www.cnblogs.com/RR-ghost/p/4645926.html
Copyright © 2011-2022 走看看