SQL:多个表需要自动增量主键吗?
发布时间:2020-12-12 16:34:30 所属栏目:MsSql教程 来源:网络整理
导读:说你在艺术家和粉丝之间有许多表.在设计桌面时,您是否设计桌面: ArtistFans ArtistFanID (PK) ArtistID (FK) UserID (FK) (ArtistID and UserID will then be contrained with a Unique Constraint to prevent duplicate data) 或者您是否为两个相关字段构建
说你在艺术家和粉丝之间有许多表.在设计桌面时,您是否设计桌面:
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) 使用以前的架构有什么优势(可能是索引?)? 解决方法ArtistFans ArtistID (PK) UserID (PK) 自动增量PK的使用在这里没有任何优势,即使父表具有它们. 我也会自动在(UserID,ArtistID)上创建一个“反向PK”索引:您将需要它,因为您将通过两列查询表. 自动编号/ ID列有它们的位置.您可以根据物理平台选择他们在规范化过程之后改进某些事情.但不适用于链接表:如果您的脑电ORM坚持,则更改ORMs … 编辑,2012年10月 请注意,您仍然需要唯一的(UserID,ArtistID)和(ArtistID,UserID)索引.添加自动增量仅使用不应使用的更多空间(在内存中,而不仅仅是磁盘上) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |