Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2004, 07:58 AM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to upermadi
Default 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?
 
Old September 27th, 2004, 01:59 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

upermadi,

Remember that the result set returned by the view has the same general form as a table and that is why the show plan shows the order details table. a view is just a virtual table.

 
Old September 28th, 2004, 12:32 AM
Registered User
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to upermadi
Default

jemacc,

But indexed view is phusically stored in database, isn't?
So the show plan must use the VDiscount2 view instead of order details table.

Actually, what I was trying is based on the example of article
"Improving Performance with SQL Server 2000 Indexed Views" from MSDN.

And it says that the query execution plan is used a Clustered Index Scan on the Vdiscount2 view.

Can you give me more explanation about it.
Thanks
 
Old September 29th, 2004, 06:51 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

use "Group By" outside the view. I mean to say that remove Group By Clause from View and use Group By while using the View.

Hope this helps


B. Anant





Similar Threads
Thread Thread Starter Forum Replies Last Post
having problem Using Indexed properties with Multi kris_rathi79 Struts 0 June 27th, 2006 07:56 AM
"validator" mis-indexed? jemptymethod BOOK: Professional Java Development with the Spring Framework 1 August 1st, 2005 09:17 AM
Indexed View jemacc SQL Server 2000 2 July 21st, 2004 05:11 AM
Stroing Objects in Vector at indexed value hanumaninme BOOK: Beginning Java 2 4 February 10th, 2004 02:04 AM
How to relate a double indexed table? izz SQL Server 2000 1 August 18th, 2003 06:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.