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

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.

主站蜘蛛池模板: 耿马| 云梦县| 临城县| 松阳县| 潞西市| 乌海市| 张北县| 宕昌县| 新津县| 隆回县| 海阳市| 石狮市| 姜堰市| 通化县| 沿河| 凤翔县| 奉节县| 东山县| 于田县| 界首市| 慈利县| 呼和浩特市| 威宁| 杂多县| 长泰县| 龙川县| 银川市| 深州市| 延吉市| 长子县| 丰城市| 太康县| 安顺市| 侯马市| 南皮县| 枣强县| 中宁县| 连城县| 太湖县| 伊金霍洛旗| 望江县|