- Learn T-SQL Querying
- Pedro Lopes Pam Lahoud
- 164字
- 2021-06-24 14:38:13
Forced parameterization
If an application tends to generate many ad hoc queries, and there is no way to modify the application to parameterize the queries, the Parameterization database option can be changed to Forced. When Forced Parameterization is turned on, SQL Server will replace ALL literal values in ALL ad hoc queries with parameter markers. Take the example of the following query executed in the AdventureWorks sample database:
SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE PersonType = N'EM' AND BusinessEntityID IN (5, 7, 13, 17, 19);
This query would be automatically parameterized under Forced Parameterization, as follows:
(@1 nchar(2), @2 int, @3 int, @4 int, @5 int, @6 int) SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE PersonType = @1 AND BusinessEntityID IN (@2, @3, @4, @5, @6);
This has the benefit of increasing the reusability of all ad hoc queries, but there are some risks to parameterizing all literal values in all queries, which will be discussed later in section The importance of parameters.
推薦閱讀
- Circos Data Visualization How-to
- Getting Started with Clickteam Fusion
- 計算機控制技術(shù)
- Visual Basic從初學(xué)到精通
- 小型電動機實用設(shè)計手冊
- 傳感器技術(shù)應(yīng)用
- 西門子S7-200 SMART PLC實例指導(dǎo)學(xué)與用
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- 聊天機器人:入門、進階與實戰(zhàn)
- 工業(yè)機器人運動仿真編程實踐:基于Android和OpenGL
- 空間站多臂機器人運動控制研究
- Statistics for Data Science
- TensorFlow Reinforcement Learning Quick Start Guide
- 從零開始學(xué)PHP
- Working with Linux:Quick Hacks for the Command Line