考虑这个示例表(假设SQL Server 2005):
create table product_bill_of_materials
(
parent_product_id int not null,
child_product_id int not null,
quantity int not null
)
Run Code Online (Sandbox Code Playgroud)
我正在考虑一个包含两个product_id列的复合主键(我肯定想要一个唯一的约束)而不是一个单独的唯一ID列.问题是,从性能的角度来看,主键是否应该聚类?
我是否还应该在每个ID列上创建索引,以便更快地查找外键?我相信这个表在读取上会比写入更多.