x
login about faq Site discussion (meta-askssc)

Query to result XML execution plan in SQL Server 2008 out of SSMS

Hi friends is there a query something like select * from [stored proc] which returns execution plan of SQL statement in XML format...I don't want to use SSMS .

more ▼

asked Aug 16 '11 at 10:53 PM in Default

pvsrinivasrao gravatar image

pvsrinivasrao
174 21 27 27

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

You can use the SET SHOWPLAN_XML ON. It needs to be executed as the only command in a batch. Then if you execute subsequent queries, you will receive XML plan for them instead of executing those queries. To disable the XML plan you execute SET SHOWPLAN_XML OFF.

SET SHOWPLAN_XML ON
GO
Your query
GO
SET SHOWPLAN_XML OFF
GO

Details related to the SHOWPLAN_XML are hre on MSDN: SET SHOWPLAN_XML (Transact-SQL)

more ▼

answered Aug 16 '11 at 11:57 PM

Pavel Pawlowski gravatar image

Pavel Pawlowski
20.3k 5 10 20

(comments are locked)
10|1200 characters needed characters left

This will give you all execution plans in the cache and a lot of statistics about the execution, like total/min/max IO/CPU/execution time etc.:

SELECT * FROM sys.dm_exec_query_stats qs
    CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
more ▼

answered Aug 16 '11 at 11:58 PM

Håkan Winther gravatar image

Håkan Winther
15k 29 35 46

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1601
x34

asked: Aug 16 '11 at 10:53 PM

Seen: 539 times

Last Updated: Aug 17 '11 at 01:07 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.