Foreign Key for either-or column?

后端 未结 3 1079
夕颜
夕颜 2021-01-19 14:12

Is it possible to have a foreign key that requires either column A or column B to have a value, but not both. And the foreign key for column A matches Table 1 and the forei

3条回答
  •  灰色年华
    2021-01-19 14:37

    It depends on which database you're working with. If you want a table Foo that has FK relationships to Table1 and to Table2 but only one at a time, then you'll need to set up either some sort of trigger (my links assume SQL Server, but the ideas's the same) or Constraint to enforce your rule that only one column have a value.

提交回复
热议问题