- Learn T-SQL Querying
- Pedro Lopes Pam Lahoud
- 120字
- 2021-06-24 14:38:13
Parameterization
Parameterization is the practice of replacing a literal value in a T-SQL statement with a parameter marker. Building on the example from the Ad hoc plan caching section, the following code block shows an example of a parameterized query executed in the AdventureWorks sample database:
DECLARE @PersonType AS nchar(2) = N'EM';
SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE PersonType = @PersonType;
In this case, the literal value, EM, is moved from the T-SQL statement itself into a DECLARE statement, and the variable is used in the query instead. This allows the query plan to be reused for different @PersonType values, whereas sending different values directly in the query string would result in a separate cached ad hoc plan.
推薦閱讀
- 工業機器人產品應用實戰
- Mastering VMware vSphere 6.5
- 可編程控制器技術應用(西門子S7系列)
- SharePoint 2010開發最佳實踐
- Splunk Operational Intelligence Cookbook
- 分析力!專業Excel的制作與分析實用法則
- 空間機械臂建模、規劃與控制
- Photoshop CS5圖像處理入門、進階與提高
- Machine Learning Algorithms(Second Edition)
- 樂高創意機器人教程(中級 上冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- Generative Adversarial Networks Projects
- Practical Network Automation
- 傳感技術基礎與技能實訓
- Oracle 11g基礎與提高
- 玩轉機器人:基于Proteus的電路原理仿真(移動視頻版)