为什么一定要添加INCLUDE,索引才会有用
本帖最后由 cyy201 于 2013-09-23 10:35:23 编辑 环境:WIN7 SP1,SQL2008 R2 SP2
CREATE TABLE [dbo].[test2](
[FID] [int] IDENTITY(1,1) NOT NULL,
[FDate] [datetime] NULL,
[FCol1] [int] NULL,
[FBillNo] [varchar](20) NULL,
CONSTRAINT [PK_test2] PRIMARY KEY CLUSTERED ([FID] ASC)
)
GO
CREATE NONCLUSTERED INDEX [IX_test2] ON [dbo].[test2]([FDate] ASC,[FID] ASC)
SELECT * FROM test2 WHERE FDate >= '2013-08-01' AND FDate <= '2013-08-31'并不走索引IX_test2,而是走聚合索引PK_test2
CREATE NONCLUSTERED INDEX [IX_test4] ON [dbo].[test4]([FDate] ASC,[FID] ASC)
INCLUDE ([FCol1],[FBillNo])