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

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.

主站蜘蛛池模板: 齐齐哈尔市| 周宁县| 益阳市| 拉萨市| 江北区| 南和县| 和林格尔县| 西藏| 商丘市| 靖远县| 清河县| 苗栗市| 隆尧县| 新晃| 河津市| 兴仁县| 自贡市| 息烽县| 屏山县| 青铜峡市| 汝南县| 邯郸县| 海淀区| 福安市| 赤水市| 玛沁县| 弥勒县| 手游| 仁化县| 大冶市| 财经| 长丰县| 聂拉木县| 临沭县| 乡城县| 涟水县| 南丰县| 镇安县| 辽源市| 武宣县| 沂源县|