SET STATISTICS TIME statement is only useful while developing as with it one can performance tune additional statement being added to the query or UDF/SP being worked on. However when one has to performance tune existing code, e.g. a SP with hundreds or thousands of lines of code, the output of this statement is pretty totally useless as it is not clear which to which SQL-statement the recorded times belong to.
Isn't there any alternatives to SET STATISTICS TIME which also show the Statements to which the recorded times belong to?
I'd create an extended events session similar to the one below:
This tracks both stored procedure and stored procedure statement completion for a procedure called
usp_foobar
. Within the event itself, there's an identifier that helps you tie together which statements were executed as a result of having executed a specific procedure (that's what theTRACK_CAUSALITY
is for).