Enforcing common foreign key in many-to-many relationship

巧了我就是萌 提交于 2019-12-08 13:23:29

My assumption is that in your current model Location has 1 restaurant and Offer has 1 Restaurant.

You can solve your problem by making a compound key on Offer: (Restaurant_ID, Offer_ID) and use this key as a foreign key from Location_Offers to Offer.

You can do the same on Location: make a compound key (Restaurant_ID, Location_ID) and use this as a foreign key from Locations_Offer to Location.

This ensures that any record in Locations_Offer that links a Location and an Offer, only links those that have a relation with the same Restaurant.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!