Composite primary key

前端 未结 8 1522
旧巷少年郎
旧巷少年郎 2020-12-15 18:37

I am working on the design of a database that will be used to store data that originates from a number of different sources. The instances I am storing are assigned unique I

8条回答
  •  借酒劲吻你
    2020-12-15 19:00

    I personally find composite primary keys to be painful. For every table that you wish to join to your "sources" table you will need to add both the source_id and id_on_source field.

    I would create a standard auto-incrementing primary key on your sources table and add a unique index on source_id and id_on_source columns.

    This then allows you to add just the id of the sources table as a foreign key on other tables.

    Generally I have also found support for composite primary keys within many frameworks and tooling products to be "patchy" at best and non-existent in others

提交回复
热议问题