假設您在藝術家和粉絲之間擁有多張桌子。當談到設計的表格,你設計的表像這樣:SQL:您是否需要用於Many-Many表的自動增量主鍵?
ArtistFans
ArtistFanID (PK)
ArtistID (FK)
UserID (FK)
(ArtistID and UserID will then be contrained with a Unique Constraint
to prevent duplicate data)
還是建立使用複合PK兩個相關領域:
ArtistFans
ArtistID (PK)
UserID (PK)
(The need for the separate unique constraint is removed because of the
compound PK)
是否有使用前一個模式的任何優點(也許索引?)?
主鍵只是一種特殊類型的索引。重複主鍵的索引只會增加開銷。 – Andomar 2009-04-26 09:24:07
訂單是重要的:這是一個不同的索引 – gbn 2009-04-26 09:42:37
好吧,有道理:) – Andomar 2009-04-26 09:44:04