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

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.

主站蜘蛛池模板: 南宫市| 读书| 张家界市| 桃园县| 娱乐| 道孚县| 天门市| 诏安县| 天津市| 三亚市| 平顺县| 翁源县| 曲沃县| 贡嘎县| 红原县| 谢通门县| 永仁县| 台州市| 陈巴尔虎旗| 三台县| 龙里县| 凤山市| 鄂尔多斯市| 平邑县| 河池市| 黔江区| 稻城县| 鄂州市| 建宁县| 呼玛县| 绥阳县| 廉江市| 辰溪县| 华蓥市| 聂拉木县| 耿马| 宝坻区| 黑河市| 孙吴县| 报价| 香格里拉县|