Do link tables need a meaningless primary key field?

前端 未结 12 1509
你的背包
你的背包 2020-12-08 14:05

I am working on a couple of link tables and I got to thinking (Danger Will Robinson, Danger) what are the possible structures of a link table and what are their pro\'s and c

12条回答
  •  一整个雨季
    2020-12-08 14:35

    The correct answer is:

    • Primary key is ('table1fk' , 'table2fk')
    • Another index on ('table2fk' , 'table1fk')

    Because:

    • You don't need an index on table1fk or table2fk alone: the optimiser will use the PK
    • You'll most likely use the table "both" ways
    • Adding a surrogate key is only needed because of braindead ORMs

提交回复
热议问题