- Learn T-SQL Querying
- Pedro Lopes Pam Lahoud
- 168字
- 2021-06-24 14:38:13
The sp_executesql procedure
The sp_executesql procedure is the recommended method for sending an ad hoc T-SQL statement to SQL Server. If stored procedures cannot be leveraged for some reason, such as when T-SQL statements must be constructed dynamically by the application, sp_executesql allows the user to send an ad hoc T-SQL statement as a parameterized query, which uses a similar caching mechanism to stored procedures. This ensures that the plan can be reused whenever the same query is executed again. Building on our example from the Ad hoc plan caching section, we can rewrite the query using sp_executesql, as in the following example which can be executed in the AdventureWorks sample database:
EXECUTE sp_executesql @stmt = N'SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE PersonType = @PersonType;'
, @params = N'@PersonType nchar(2)'
, @PersonType = N'EM';
This ensures that any time the same query is sent with the same parameter markers, the plan will be reused, even if the statement is dynamically generated by the application.
- Getting Started with MariaDB
- STM32G4入門與電機控制實戰:基于X-CUBE-MCSDK的無刷直流電機與永磁同步電機控制實現
- Mastering Machine Learning Algorithms
- OpenStack Cloud Computing Cookbook(Second Edition)
- 四向穿梭式自動化密集倉儲系統的設計與控制
- 現代傳感技術
- 可編程序控制器應用實訓(三菱機型)
- 計算機組網技術
- Dreamweaver CS6中文版多功能教材
- Dreamweaver+Photoshop+Flash+Fireworks網站建設與網頁設計完全實用
- Drupal高手建站技術手冊
- Mastering Predictive Analytics with scikit:learn and TensorFlow
- 智慧未來
- 人工智能:智能人機交互
- Linux常用命令簡明手冊