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

  • Learn T-SQL Querying
  • Pedro Lopes Pam Lahoud
  • 187字
  • 2021-06-24 14:38:14

Prepared statements

Another method for sending parameterized T-SQL statements to SQL Server is by using prepared statements. Leveraging prepared statements involves the following three different system procedures:

  • sp_prepare: Defines the statement and parameters that are to be executed, creates an execution plan for the query, and sends a statement handle back to the caller, which can be used for subsequent executions
  • sp_execute: Executes the statement defined by sp_prepare by sending the statement handle along with any parameters to SQL Server
  • sp_unprepare: Discards the execution plan created by sp_prepare for the query specified by the statement handle

The first two procedures can optionally be combined into a single sp_prepexec statement to save a roundtrip to the server.

This method is not generally recommended for plan reuse as it is a legacy construct and may not take advantage of some of the benefits of parameterized statements that sp_executesql and stored procedures can leverage. It is worth mentioning, however, because it is used by some cross-platform database connectivity libraries, such as Open Database Connectivity (ODBC) or Java Database Connectivity (JDBC), as the default mechanism for sending queries to SQL Server.

主站蜘蛛池模板: 江山市| 湟源县| 贵港市| 兴安县| 三明市| 永靖县| 宜都市| 文山县| 临邑县| 丁青县| 晋中市| 新巴尔虎右旗| 姜堰市| 永安市| 融水| 民勤县| 日喀则市| 大竹县| 沂南县| 上思县| 高淳县| 汽车| 郯城县| 大方县| 昭平县| 乌拉特前旗| 海安县| 明溪县| 莱州市| 吴堡县| 额尔古纳市| 垫江县| 抚顺县| 东海县| 德格县| 寻乌县| 柳江县| 康定县| 克山县| 靖宇县| 壤塘县|