WEB开发网
开发学院数据库MSSQL Server SQL Server2005查询计划指南 阅读

SQL Server2005查询计划指南

 2007-07-31 09:47:37 来源:WEB开发网   
核心提示: {HASH | ORDER} GROUP{CONCAT | HASH | MERGE} UNION{LOOP | MERGE | HASH} JOINFAST number_rowsFORCE ORDERMAXDOP number_of_processorsOPTIMIZE FOR ( @
{HASH | ORDER} GROUP
{CONCAT | HASH | MERGE} UNION
{LOOP | MERGE | HASH} JOIN
FAST number_rows
FORCE ORDER
MAXDOP number_of_processors
OPTIMIZE FOR ( @variable_name = literal_constant ) [ ,…n ]
RECOMPILE
ROBUST PLAN
KEEP PLAN
KEEPFIXED PLAN
EXPAND VIEWS
MAXRECURSION number
USE PLAN <xmlplan>

使用示例:

以下二个存储过程创造和处理计划指南

sp_create_plan_guide
sp_control_plan_guide

1.sp_create_plan_guide

创建用于将查询提示与数据库中的查询进行关联的计划指南

语法:

sp_create_plan_guide [ @name = ] N'plan_guide_name'
   , [ @stmt = ] N'statement_text'
   , [ @type = ] N'{ OBJECT | SQL | TEMPLATE }'
   , [ @module_or_batch = ]
    {
          N'[ schema_name. ] object_name'
     | N'batch_text'
     | NULL
    }
   , [ @params = ] { N'@parameter_name data_type
[ ,...n ]' | NULL }
   , [ @hints = ] { N'OPTION ( query_hint [ ,...n ] )'
| NULL }

示例

sp_create_plan_guide
@name = N'PlanGuideTest',
@stmt = N'SELECT COUNT(*) AS Total
FROM Sales.SalesOrderHeader h, Sales.SalesOrderDetail d
WHERE h.SalesOrderID = d.SalesOrderID and h.OrderDate
BETWEEN ''1/1/2000'' AND ''1/1/2005'' ',
@type = N'SQL',
@module_or_batch = NULL,
@params = NULL,
@hints = N'OPTION (MERGE JOIN)'
GO

上一页  1 2 3 4  下一页

Tags:SQL Server 查询

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接