简体   繁体   中英

Split single table to many-to-many relationship

I have a table that looks like the following:

在此处输入图片说明

I want to split this to 3 different tables with a PK-FK relationship. Essentially a province can have many state, a state can have many cities. What is the best way to do this in one shot using a SQL query if it's even possible? Or using tools like phpmyadmin.

Province table:

Province_ID (PK)
Province_Name

State table:

State_ID (PK)
State_Name
Province_ID (FK)
AreaCode

Citi table:

Citi_ID (PK)
Citi_Name
State_ID (FK)
Citi_Code

I don't think there's any tools that can help you normalize this table automatically. So you have to create these tables by code then using sql query to insert values into it

您可以按以下方式对其进行分区:

Prov Table with Prov_ID as PK.

State Table with State_ID as PK and Prov_ID as FK

City Table with City_ID as PK and State_ID as FK and Prov_ID as FK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM