可以對兩個可能的表之一執行 MySQL 外鍵嗎? - Possible to do a MySQL foreign key to one of two possible tables?

問題:

Well here's my problem I have three tables;嗯,這是我的問題,我有三張桌子; regions, countries, states.地區、國家、州。 Countries can be inside of regions, states can be inside of regions.國家可以在區域內,國家可以在區域內。 Regions are the top of the food chain.區域是食物鏈的頂端。

Now I'm adding a popular_areas table with two columns;現在我要添加一個包含兩列的流行區域表; region_id and popular_place_id. region_id 和popular_place_id。 Is it possible to make popular_place_id be a foreign key to either countries OR states.是否有可能使popular_place_id 成爲國家州的外鍵。 I'm probably going to have to add a popular_place_type column to determine whether the id is describing a country or state either way.我可能不得不添加一個popular_place_type 列來確定id 是在描述一個國家還是州。


解決方案:

參考一: https://en.stackoom.com/question/1qiv
參考二: https://stackoom.com/question/1qiv
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章