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

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.

主站蜘蛛池模板: 兴文县| 吴桥县| 准格尔旗| 桂平市| 老河口市| 武穴市| 松溪县| 新野县| 红桥区| 渭源县| 滕州市| 县级市| 军事| 博乐市| 江门市| 仁布县| 乌鲁木齐县| 米林县| 绍兴县| 宣汉县| 静乐县| 清水河县| 周宁县| 揭阳市| 开远市| 湟源县| 女性| 泗洪县| 玉环县| 彩票| 闻喜县| 阿荣旗| 福海县| 革吉县| 乌拉特前旗| 蕉岭县| 大关县| 丘北县| 万宁市| 时尚| 延津县|