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

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.

主站蜘蛛池模板: 靖西县| 于都县| 宁乡县| 铅山县| 湄潭县| 大连市| 宁陵县| 保山市| 阿瓦提县| 乌鲁木齐县| 通许县| 韶关市| 海南省| 桃源县| 仲巴县| 九龙坡区| 衡南县| 泽普县| 申扎县| 博野县| 广汉市| 浏阳市| 常山县| 张北县| 大城县| 公主岭市| 鄂伦春自治旗| 潍坊市| 民丰县| 梁河县| 肥西县| 晋城| 虞城县| 栖霞市| 晋宁县| 祁连县| 嘉峪关市| 南投市| 平江县| 孙吴县| 龙陵县|