Exporting plans to a user table

sp_export_qpgroup copies all plans for a specific user from an abstract plan group to a user table. This example copies plans owned by the Database Owner (dbo) from the fast_plans group, creating a table called transfer:

sp_export_qpgroup dbo, fast_plans, transfer

sp_export_qpgroup uses select...into to create a table with the same columns and datatypes as sysqueryplans. If you do not have the select into/bulkcopy/pllsort option enabled in the database, you can specify the name of another database. This command creates the export table in tempdb:

sp_export_qpgroup mary, ap_stdout, "tempdb..mplans"

The table can be copied out using bcp, and copied into a table on another server. The plans can also be imported to sysqueryplans in another database on the same server, or the plans can be imported into sysqueryplans in the same database, with a different group name or user ID.