Press "Enter" to skip to content

SET STATISTICS XML

Daniel Hutmacher explains how SET STATISTICS XML will generate execution plans for certain segments of code:

But sometimes you want to run a series of statements or procedures where you only want the execution plan for some of the statements. Here’s how:

The actual execution plan is enabled by turning on SET STATISTICS XML., not unlike enabling STATISTICS IO or TIME. And just like SET NOCOUNT, the SET statements apply to the current context, which could be a stored procedure, a session, etc. When this context ends, the setting reverts to that of the parent context.

I see code snippets with STATISTICS IO and TIME fairly regularly, but almost never see STATISTICS XML; instead, I see people (including myself) hit Ctrl-M or select the “Include Actual Execution Plan” button when generating execution plans is desirable.

One Comment

  1. Daniel Hutmacher
    Daniel Hutmacher 2016-05-23

    That’s the point – use Ctrl+M like you’re used to, but this way you won’t have to see the execution plan of everything that happens, only the particular statements you’re interested in. 🙂

    Thanks for the reblog!

Comments are closed.