2

When executing T-SQL queries via Management Studio, I can use SET STATISTICS PROFILE ON to capture statistics and query execution plan in a nice-looking format as a text.

How can I gather the query execution plan after I execute stored procedures, so that I can analyze it programmaticaly rather than analyze it visually in SSMS "messages" tab?

I can use SET SHOWPLAN_ALL ON but I would like to see actual plan rather than estimated one, and it has same issue: How can get the outcome automatically?

I can also get XML plan from DMVs, but I wonder how can I get the text-formatted one.

I found very similar post here but it did not

here is an example of what I call "nice-looking text format": |--Nested Loops(Inner Join, OUTER REFERENCES:([AdventureWorks].[Person].[Address].[AddressID])) |--Filter(WHERE:(STARTUP EXPR(suser_sname()=CONVERT_IMPLICIT(nvarchar(4000),[@2],0)))) | |--Index Scan(OBJECT:([AdventureWorks].[Person].[Address].[IX_Address_StateProvinceID])) |--Clustered Index Seek(OBJECT:([AdventureWorks].[Person].[Address].[PK_Address_AddressID]), SEEK:([AdventureWorks].[Person].[Address].[AddressID]=[AdventureWorks].[Person].[Address].[AddressID]), WHERE:([AdventureWorks].[Person].[Address].[City]=N'Snohomish') LOOKUP ORDERED FORWARD)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stas Prihod'co
  • 864
  • 9
  • 13

0 Answers0