开发者

SQL server execution plan

How can I capture SQL execution plan for queries . Someone told that I can retrieve them through syste开发者_如何转开发m 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

SQL server execution plan

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜