我为多对多关系创建了一个连接表。
该表只有 2 个列,ticketid
并且groupid
典型的数据是
groupid ticketid
20 56
20 87
20 96
24 13
24 87
25 5
我的问题是在创建复合键时我应该ticketid
遵循groupid
CONSTRAINT [PK_ticketgroup] PRIMARY KEY CLUSTERED
(
[ticketid] ASC,
[groupid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
或以另一种方式,groupid
然后ticketid
CONSTRAINT [PK_ticketgroup] PRIMARY KEY CLUSTERED
(
[groupid] ASC,
[ticketid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
在选项 1 中搜索索引是否会更快,因为ticketid's
它们比 groupid 更有可能是唯一的,并且它们将位于复合键的开头?或者这可以忽略不计?