Using SQL Server 2005, I am experiencing easily reproducible data corruption when stacking indexed views. The following code should clarify things:CREATE TABLE TemporaryTable ( A INT, B INT, C DECIMAL)INSERT INTO TemporaryTable VALUES (1,1,1.0)GOCREATE VIEW dbo.AggregateView WITH SCHEMABINDING AS SELECT A, B, SUM(ISNULL(C, 0)) AS C, COUNT_BIG(*) AS IgnoreFROM dbo.TemporaryTable GROUP BY A, BGOCREATE UNIQUE CLUSTERED INDEX AggregateViewIndex ON AggregateView(A, B)GOCREATE VIEW dbo.NestedAggregateView WITH SCHEMABINDING AS SELECT A, SUM(ISNULL(C, 0)) AS C, COUNT_BIG(*) AS [Irrelevant]FROM dbo.AggregateView WITH (NOEXPAND) GROUP BY AGOCREATE UNIQUE CLUSTERED INDEX NestedAggregateViewIndex ON NestedAggregateView(A)UPDATE TemporaryTable SET C = 2.0SELECT A, SUM(ISNULL(C, 0)) AS CFROM dbo.AggregateView WITH (NOEXPAND) GROUP BY ASELECT A, C FROM NestedAggregateView WITH (NOEXPAND)DROP VIEW NestedAggregateViewDROP VIEW AggregateViewDROP TABLE TemporaryTable
I get different results...Not using index: (1,2)Using index: (1,1)Analyzing the update shows that AggregateView was updated, but that NestedAggregateView was not.Any suggestions other than the obvious solution of simply not nesting the views?Cheers,Qest