我有这个 M2M 连接表:
CREATE TABLE [dbo].[RecipientsDonors]
(
[RecipientId] [int] NOT NULL,
[DonorId] [int] NOT NULL,
CONSTRAINT [PK_RecipientsDonors] PRIMARY KEY CLUSTERED
(
[RecipientId] ASC,
[DonorId] ASC
)
)
我也有这两个索引:
CREATE NONCLUSTERED INDEX [IX_RecipientsDonors_RecipientId] ON [dbo].[RecipientsDonors]
(
[RecipientId] ASC
)
CREATE NONCLUSTERED INDEX [IX_RecipientsDonors_DonorId] ON [dbo].[RecipientsDonors]
(
[DonorId] ASC
)
我使用这两个索引的目的是加快单列查找速度。
既然主键存在,那么索引是否是多余的呢?或者它们是必要的,因为主键包含两列?