简体   繁体   中英

SQL server execution plan

How can I capture SQL execution plan for queries. Someone told that I can retrieve them through system tables

As gbn points out, there are a number of different ways that you can review the execution plans for queries. Given that your question makes reference to the use of system tables I assume that your are talking about the Dynamic Management Views (DMV's) and that your are therefore also only interested in query plans that are currently in the plan cache.

If you are interested in identifying the query plan for a specific query from the plan cache then you can use a query of the form like below:

SELECT  deqs.plan_handle ,
        deqs.sql_handle ,
        execText.text
FROM    sys.dm_exec_query_stats deqs
        CROSS APPLY sys.dm_exec_sql_text(deqs.plan_handle) AS execText
WHERE   execText.text LIKE '%QueryText%'

For further reading, take a look at the article DMVs for Query Plan Metadata


If say you are more interested in reviewing the performance of your most poorly performing queries, that are currently referenced in the plan cache, you can make use of the excellent and freely available SQL Server Performance Dashboard Reports.


There are of course other methods for viewing query plans but without knowing exactly what it is that you are trying to achieve, these may not be appropriate to your needs.

Quick search on MSDN will get you this: http://msdn.microsoft.com/en-us/library/ms189747.aspx

Hope it helps.

This question could be clearer but I imagine some people coming here might be looking for the easiest way to get an execution plan for a query

The easiest way to capture the execution plan of a query is to click the "Include Actual Execution Plan" button and execute the query on SSMS

包括实际执行计划按钮

Results will be displayed as a tab together with the query results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM