Where should I store a foreign key?

后端 未结 4 576
猫巷女王i
猫巷女王i 2021-01-31 09:52

If I have a relationship between two tables (both tables have their own primary keys) what should guide my decision as to which table should store the foreign key? I understand

4条回答
  •  -上瘾入骨i
    2021-01-31 10:31

    "What is a systematic way of making that decision though?"

    There appear to be two choices: The "One" side as FK's to the "Many side", or the "Many" Side has FK's to the "One" side.

    Let's actually look a the choices.

    • All the rows of the "Many" side can easily reference one row on the "One" side.

    • The one row on the "One" side cannot ever reference ALL of the rows on the "Many" side.

    Only one technique works: "Many" side has FK to "One" side.

    There is only one actual implementation choice. There's no "decision".

提交回复
热议问题