Copying a plan to another group

sp_copy_qplan copies an abstract plan from one group to another existing group. This example copies the plan with plan ID 316528161 from its current group to the prod_plans group:

sp_copy_qplan 316528161, prod_plans

sp_copy_qplan checks to make sure that the query does not already exist in the destination group. If a possible conflict exists, it runs sp_cmp_qplans to check plans in the destination group. In addition to the message printed by sp_cmp_qplans, sp_copy_qplan prints messages when:

If there is a hash-key collision, the plan is copied. If the plan already exists in the destination group or if it would give an association key collision, the plan is not copied. The messages printed by sp_copy_qplan contain the plan ID of the plan in the destination group, so you can use sp_help_qplan to check the query and plan.

A System Administrator or the Database Owner can copy any abstract plan. Other users can copy only plans that they own. The original plan and group are not affected by sp_copy_qplan. The copied plan is assigned a new plan ID, the ID of the destination group, and the user ID of the user who ran the query that generated the plan.