Using set commands to capture and associate plans

At the session level, any user can enable and disable capture and use of abstract plans with the set plan dump and set plan load commands. The set plan replace command determines whether existing plans are overwritten by changed plans.

Enabling and disabling abstract plan modes takes effect at the end of the batch in which the command is included (similar to showplan). Therefore, change the mode in a separate batch before you run your queries:

set plan dump on
go
/*queries to run*/
go

Any set plan commands used in a stored procedure do not affect the procedure in which they are included, but remain in effect after the procedure completes.