官术网_书友最值得收藏!

Stored procedures

A stored procedure is a group of one or more T-SQL statements that is stored as an object in a SQL Server database. Stored procedures are like procedures in other programming languages in that they can accept input parameters and return output parameters, they can contain control-flow logic, such as conditional statements (IF … ELSE), loops (WHILE), and error handling (TRY … CATCH), and they can return a status value to the caller that indicates success or failure. They can even contain calls to other stored procedures. There are many benefits to using stored procedures, but in this section, we will focus mainly on their benefit of reducing the overhead of the compilation process through caching.

The first time a stored procedure is executed, SQL Server compiles and optimizes the T-SQL within the procedure, and the resulting execution plan is cached for future use. Every subsequent call to the procedure reuses the cached plan, until the plan is removed from the cache due to any of the following reasons:

  • Memory pressure
  • Server restart
  • Plan invalidation, that is, when the underlying objects are changed in some way or a significant amount of data is changed

Stored procedures are the preferred method for plan caching as they provide the most effective mechanism of caching and reusing query plans in SQL Server.

主站蜘蛛池模板: 区。| 平阳县| 上高县| 聂拉木县| 湘潭市| 星座| 襄汾县| 新安县| 广水市| 岳阳市| 库尔勒市| 富民县| 德阳市| 长顺县| 惠东县| 肥西县| 达孜县| 开封市| 阜宁县| 舞阳县| 曲阳县| 昌吉市| 利川市| 普格县| 临江市| 巫山县| 民和| 桑植县| 新干县| 黎川县| 威信县| 工布江达县| 阳高县| 山东| 恭城| 磐安县| 本溪市| 和政县| 大关县| 连平县| 常熟市|