Need Help : Indexed View
I'm trying to use an indexed view but I found that it didn't work.
I used Northwind database. Here's the code:
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL ,ARITHABORT,
QUOTED_IDENTIFIER,ANSI_NULLS ON
GO
CREATE VIEW Vdiscount2 WITH SCHEMABINDING
AS
SELECT SUM(UnitPrice*Quantity)AS SumPrice, SUM(UnitPrice*Quantity*(1.00-Discount))AS SumDiscountPrice, SUM(UnitPrice*Quantity*Discount)AS SumDiscountPrice2, COUNT_BIG(*) AS Count, ProductID
FROM dbo.[Order Details]
GROUP BY ProductID
GO
CREATE UNIQUE CLUSTERED INDEX VDiscountInd ON Vdiscount2 (ProductID)
After that I use execution plan and run this query
SELECT * FROM VDiscount2
WHERE sumPrice>10000
But the execution plan showed the [Order Details] was used instead of VDiscount2 view. How could this happened since the VDiscount2 view is physically stored in database.
Please give me some explanation about it?
|