USE AdventureWorks2017;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
ALTER DATABASE CURRENT SET PARAMETERIZATION SIMPLE;
GO
-- None (0)
SELECT COUNT_BIG(*)
FROM Production.Product AS P
WHERE P.Color = N'Red';
GO
-- User (1)
EXECUTE sys.sp_executesql
@stmt = N'
SELECT COUNT_BIG(*)
FROM Production.Product AS P
WHERE P.Color = @Color;',
@params = N'@Color nvarchar(15)',
@Color = N'Red';
GO
-- Simple (2)
SELECT A.AddressID
FROM Person.[Address] AS A
WHERE A.AddressLine1 = N'1 Smiling Tree Court';
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
ALTER DATABASE CURRENT SET PARAMETERIZATION FORCED;
GO
-- Forced (3)
SELECT COUNT_BIG(*)
FROM Production.Product AS P
WHERE P.Color = N'Red';
该
StatementParameterizationType
属性指示应用于语句的参数化类型。这些值记录在
sys.query_store_query
:它仅出现在执行后(“实际”)计划的根节点上。
还必须启用查询存储才能看到此属性(例如在 SSMS 中)。
AdventureWorks演示: