解決SQL2k降序索引上使用對比條件更新或刪除的bug我在SQL server 2000 enterPRise 和 personal 都試過了, 每次都這樣。:( 詳細情況看我的回貼:
SQl server 7.0 中的確沒有問題, sql 2000 中(enterprise 和 personal版本都可以),
表要有聚簇索引,并且索引的順序是降序,
例如 按下列DDL sql 建立的表 CREATE TABLE [AType] ( [AID] [int] NOT NULL , [name] [varchar(20)] NOT NULL , CONSTRAINT [PK_DateType] PRIMARY KEY CLUSTERED ([AID] DESC) ON [PRIMARY] , ) ON [PRIMARY]
添一些數(shù)據(jù)后, AID 分別分布在1-100之間 INSERT INTO [AType] VALUES(1,'a') INSERT INTO [AType] VALUES(50,'b') INSERT INTO [AType] VALUES(100,'c') 做 select from atype where Aid < 50 go delete from Atype where AID < 50 go select from atype where Aid < 50 最后一句查詢?nèi)匀挥杏涗涊敵? :(
by 怡紅公子 報告已經(jīng)發(fā)送給MSSQL開發(fā)小組,他們承認這一錯誤。 在沒有新的補丁出來之前,給出以下建議: 不要在單列上使用降序索引,因為這并沒有在性能上帶來好處,僅僅是省略了Order by field desc幾個字而已,用qa的show plan看一下就知道了,不管有沒有order by或者不管是asc還是desc,都沒有這項開銷的(在聚簇索引上)。 降序索引一般是用于復(fù)合索引的,這可能是這個bug出現(xiàn)的原因。 原文: Note that there is no need to create a descending index on a single column because SQL Server can traverse an ascending index backwards when appropriate. Descending is normally used only in composite indexes. This is probably why the bug surfaces here