--=========================== --查询语句 EXEC [sys].[sp_executesql] N' SELECT COUNT(1) FROM dbo.TB1 WHERE RID>@RID',N'@RID INT',@RID=10 --=========================== --为该语句创建执行计划 EXEC [sys].[sp_create_plan_guide] @name=N'Guide3', @type=N'SQL', @stmt=N' SELECT COUNT(1) FROM dbo.TB1 WHERE RID>@RID', @params=N'@RID INT', @hints=N'option(optimize for(@RID=1))' --执行然后查看XML的执行计划,可以找到Guide3的执行计划名 --<StmtSimple StatementCompId="2" StatementEstRows="1" --StatementId="1" StatementOptmLevel="FULL" --StatementSubTreeCost="5.29194" --StatementText="SELECT COUNT(1)
FROM dbo.TB1 
WHERE RID>@RID" --StatementType="SELECT" PlanGuideDB="master" --PlanGuideName="Guide3" QueryHash="0x500C0FFF16D7A745" --QueryPlanHash="0x80999B12FE88D9D1">