문제

In SQL Server, is there some magic SQL I can preprend my SQL query to get an estimated query cost rather than the query executed?

Possibly something like the below is my best guess myself.. seems very verbose though

SET STATISTICS PROFILE ON
GO

SELECT *  FROM [Account]

GO 
SET STATISTICS PROFILE OFF
도움이 되었습니까?

해결책

SET SHOWPLAN_XML ON;
GO
SELECT * FROM master..spt_values
GO
SET SHOWPLAN_XML OFF;

STATISTICS PROFILE gives you the actual plan, which means that the query will get executed. SHOWPLAN_XML or SHOWPLAN_ALL (text plan) will give you the estimated plan without executing the query. You can click on the xml result to see the graphical plan. If that does not work use SQL Sentry Plan Explorer (free) to show the plan.

다른 팁

You can use the execution plan which would give you the cost. You can do this by selecting it in the right click context menu

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top