-----------------------------------------------------------------------------
/*
SQL Server در Execution Plan آشنایی با مفهوم  
Site:        http://www.NikAmooz.com
Instagram:   https://instagram.com/nikamooz/
Telegram:	 https://telegram.me/nikamooz
Created By:  Iman Bagheri
*/
-----------------------------------------------------------------------------
 --Execution Plan بررسی انواع فرمت های 
 GO
 
/*
Actual Execution Plan 
قالب گرافیکی (Ctrl + M)
*/
SELECT 
	SalesPersonID, YEAR(orderdate) AS OrderYear,
	COUNT(*) AS NumOrders 
FROM Sales.SalesOrderHeader 
WHERE CustomerID = 29994 
GROUP BY SalesPersonID, YEAR(OrderDate) 
HAVING COUNT(*) > 1 
ORDER BY OrderYear DESC 
GO
/*
Actual Execution Plan 
قالب متنی (STATISTICS PROFILE)
*/
SET STATISTICS PROFILE ON
GO
SELECT 
	SalesPersonID, YEAR(orderdate) AS OrderYear,
	COUNT(*) AS NumOrders 
FROM Sales.SalesOrderHeader 
WHERE CustomerID = 29994 
GROUP BY SalesPersonID, YEAR(OrderDate) 
HAVING COUNT(*) > 1 
ORDER BY OrderYear DESC 
GO
SET STATISTICS PROFILE OFF
GO
/*
Actual Execution Plan 
XML قالب (STATISTICS XML)
*/
SET STATISTICS XML ON
GO
SELECT 
	SalesPersonID, YEAR(orderdate) AS OrderYear,
	COUNT(*) AS NumOrders 
FROM Sales.SalesOrderHeader 
WHERE CustomerID = 29994 
GROUP BY SalesPersonID, YEAR(OrderDate) 
HAVING COUNT(*) > 1 
ORDER BY OrderYear DESC 
GO
SET STATISTICS XML OFF
