我有一张桌子
Table
Email_Address
Name
contact_No
city
Pincode
state
country
我分为两部分
Table1
Email_Address(PK)
Name
contact_No
city
table2
city
Pincode
state
country
我如何维持这张桌子之间的关系。
答案 0 :(得分:1)
City
将是table2
的主键和Table1
中的外键。 (但这需要城市名称是全球唯一的,并且每个城市名称只有一个密码)。
您需要确保单个city
只有一个Pincode
。
如果不是这种情况,可以使用Pincode
作为主要/外键而不是city
。
更新:由于显然有些pincodes跨越多个城市,您可能需要使用冗余或引入人工密钥。另请参阅评论中的类似问题的链接。