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

Simple parameterization

In order to minimize the impact of ad hoc queries, SQL Server will automatically parameterize some simple queries by default. This is called Simple parameterization and is the default setting of the parameterization database option. With parameterization set to Simple, SQL Server will automatically replace literal values in an ad hoc query with parameter markers in order to make the resulting query plan reusable. This works for some queries, but there is a very small class of queries that can be parameterized this way.

As an example, the query we introduced previously in the Parameterization section would not be automatically parameterized in simple mode because it is considered unsafe. This is because different PersonType values may yield a different number of rows, and thus require a different execution plan. However, the following query executed in the AdventureWorks sample database would qualify for simple automatic parameterization:

SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE BusinessEntityID = 5;

This query would not be cached as is. SQL Server would convert the literal value of 5 to a parameter marker, and it would look something like this in the cache:

(@1 tinyint) SELECT LastName, FirstName, MiddleName
FROM Person.Person
WHERE BusinessEntityID = @1;
主站蜘蛛池模板: 股票| 临城县| 高雄县| 杭州市| 昌江| 清镇市| 北辰区| 耒阳市| 阿拉善右旗| 乐山市| 忻州市| 巴彦淖尔市| 清水河县| 临沭县| 松江区| 淳化县| 长岛县| 沙河市| 应城市| 呼伦贝尔市| 南开区| 巧家县| 临沭县| 安龙县| 宕昌县| 尖扎县| 孟村| 山西省| 兴隆县| 杭锦后旗| 清丰县| 嘉鱼县| 阿荣旗| 泰兴市| 珲春市| 乐亭县| 海南省| 乌兰察布市| 元朗区| 绥宁县| 教育|