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

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.

主站蜘蛛池模板: 九江市| 宜兴市| 达孜县| 蒙山县| 南雄市| 东乡族自治县| 华容县| 上杭县| 奎屯市| 普安县| 孝感市| 张家口市| 惠水县| 阿鲁科尔沁旗| 成安县| 罗定市| 德兴市| 东城区| 西峡县| 志丹县| 宁津县| 聂拉木县| 铅山县| 华宁县| 手游| 兖州市| 黄山市| 广宗县| 云林县| 滦南县| 宁河县| 富锦市| 庐江县| 广灵县| 翁牛特旗| 永安市| 务川| 城固县| 惠东县| 吉安市| 庐江县|