sqlnewbie
sqlnewbie

Reputation: 867

Query to result 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 .

Upvotes: 1

Views: 685

Answers (1)

Mikael Eriksson
Mikael Eriksson

Reputation: 138970

You can get the XML query plan by using sys.dm_exec_cached_plans and sys.dm_exec_text_query_plan.

select x.query_plan
from sys.dm_exec_cached_plans as p
  cross apply sys.dm_exec_text_query_plan(p.plan_handle,  0, -1) as x
where p.objtype = 'proc' and
      x.objectid = object_id('StoredProcName', 'P')

Upvotes: 1

Related Questions