我有几个表:company
、customer
、company_has_customer
和transaction
。
company_has_customer
是一个多对多联结表,使用company
和customer
作为其 PK。
在整个数据库的几乎所有情况下,company
和customer
都用于标识一条记录(例如在transaction
表中)。
我的问题是我是否应该在transaction
表中创建外键以分别指向company_has_customer
或指向两个表(company
, customer
)?
我认为,最好将这些 FK 发送到参照完整性,company_has_customer
以确保transaction
仅在公司与客户之间存在关系时才插入记录。是否有任何标准或约定来支持我的预感?