If the base tables are so large that even the single scan required to produce the summary tables is problematic and you can afford the performance degradation resulting from modifying the base tables, you have another option: using indexed views. (See Kalen Delaney, 'Introducing Indexed Views,' May 2000, InstantDoc ID #8410, for information about indexed views.) . . . "
USE Northwind
SELECT
CONVERT(CHAR(6), OrderDate, 112) AS omonth,
SUM(Quantity) AS qty
INTO MonthlyOrders
FROM Orders AS O
JOIN 'Order Details' AS OD
ON O.OrderID = OD.OrderID
GROUP BY CONVERT(CHAR(6), OrderDate, 112)
CREATE UNIQUE CLUSTERED INDEX IDX_UC_omonth ON MonthlyOrders(omonth)
Tuesday, April 10, 2007
Practical Implementations
Practical Implementations: "query produces the MonthlyOrders summary table, which is structurally similar to the Sales table I presented in Listing 1: