整个架构是错误的!您对数据库规范化了解多少?您的架构至少不符合第三范式的要求。举个例子:
你有国家:
-CountryName1
-CountryName2
-CountryName3
你有地区:
-RegionOfCountry1_a
...
-RegionOfCountry3_a
你有城市:
-City_1_Of_Country1_Region_a
...
-City_3_Of_Country3_Region_a
在树视图中的示例数据将是:
-CountryName1
|_ -RegionOfCountry1_a
|_ -CityOf_Country1_Region_a
|_ -City_1_Of_Country1_Region_a
|_ -City_2_Of_Country1_Region_a
|_ -City_3_Of_Country1_Region_a
|_ -CityOf_Country1_Region_b
|_ -City_1_Of_Country1_Region_b
|_ -City_2_Of_Country1_Region_b
|_ -City_3_Of_Country1_Region_b
|_ -CityOf_Country1_Region_c
|_ -City_1_Of_Country1_Region_c
|_ -City_2_Of_Country1_Region_c
|_ -City_3_Of_Country1_Region_c
|_ -RegionOfCountry1_b
|_ -CityOf_Country2_Region_a
|_ -City_1_Of_Country2_Region_a
|_ -CityOf_Country2_Region_b
|_ -City_1_Of_Country2_Region_b
|_ -CityOf_Country2_Region_c
|_ -City_1_Of_Country2_Region_c
|_ -RegionOfCountry1_c
|_ -CityOf_Country2_Region_a
|_ -City_1_Of_Country2_Region_c
...
-CountryName2
|_ -SecondCountry
|_ -MegaCityCountry3
...
-CountryName3
|_ -MegaRegionCountry3
|_ -MegaCityCountry3
您的房屋表具有外键约束(country_id、city_id、region_id),它“链接”到这 3 个表。它提供了创建错误记录的可能性,例如:
*name = "MyHouse with address data from a far galaxy"
country_id = CountryName**1**
region_id = RegionOfSecondCountry (from CountrName**2**)
city_id = MegaCityCountry3 (from -CountryName**3**)*
这意味着下一步:你不知道规范化要求或者你不预测传递依赖
尝试下一步
----------------
Table "**houses**"
----------------
id
houseNumber
description
*fk_city_id*
----------------
fk_city_id 对城市.id 的引用:
----------------
table "**cities**"
----------------
id
name
*fk_region_id*
----------------
fk_region_id 对区域.id 的引用:
----------------
table "**regions**"
----------------
id
name
*fk_country_id*
----------------
fk_country_id 对国家.id 的引用:
----------------
table "**countries**"
----------------
id
name
----------------
PS >>对不起我的英语不好