create plan

Description

Creates an abstract plan.

Syntax

create plan query plan 
	[into group_name]
	[and set @new_id]

Parameters

query

is a string literal, parameter, or local variable containing the SQL text of a query.

plan

is a string literal, parameter, or local variable containing an abstract plan expression.

into group_name

specifies the name of an abstract plan group.

and set @new_id

returns the ID number of the abstract plan in the variable.

Examples

Example 1

Creates an abstract plan for the specified query:

create plan "select * from titles where price > $20" " (t_scan titles)"

Example 2

Creates an abstract plan for the query in the dev_plans group, and returns the plan ID in the variable @id:

declare @id int
create plan "select au_fname, au_lname from authors where au_id = '724-08-9931' " 
" (i_scan au_id_ix authors)"
into dev_plans
and set @id
select @id

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

No permission is required to use create plan.

See also

Commands set plan

Documentation Performance and Tuning Guide: Optimizer and Abstract Plans.

System procedures sp_add_qpgroup, sp_configure "enable literal autoparam", sp_find_qplan, sp_help_qplan, sp_set_qplan