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

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;
主站蜘蛛池模板: 阿克| 浪卡子县| 景德镇市| 偏关县| 千阳县| 大渡口区| 潼关县| 黄龙县| 滨州市| 稻城县| 长宁县| 汝州市| 通州市| 老河口市| 丁青县| 邹平县| 新巴尔虎右旗| 西乌| 太保市| 拉孜县| 鄂托克前旗| 房产| 芜湖市| 新丰县| 比如县| 灌阳县| 陈巴尔虎旗| 鄂尔多斯市| 蓬安县| 浮梁县| 黔江区| 华安县| 高碑店市| 双城市| 扎兰屯市| 高尔夫| 景东| 仲巴县| 安塞县| 微山县| 衡阳市|