Description
The article here is followed by the previous MySQL table one-to-many write.
Multiple-to-many tables
Can be understood as polygamy and polygamy.
Men's Watch:
Nid |
Name |
1 |
Xxx |
2 |
yyy |
3 |
zzz |
Women's Watch:
Nid |
Name |
1 |
Aaa |
2 |
Bbb |
3 |
Ccc |
To create a relationship between two tables, you can use a foreign key to bind each table by adding one column to each other, allowing them to constrain each other.
However, this is not ideal, after all, to modify the table.
In general, a single table is created, and the table has 2 data and 2 table IDs associated with each other. This table can be called a relational table.
Practice:
2 foreign keys are set on the relational table, respectively, associated with the corresponding male and female tables.
Nid |
man_id |
women_id |
1 |
1 |
3 |
2 |
3 |
1 |
3 |
2 |
2 |
Description
Set the two foreign keys on the relational table so that man_id corresponds to the nid,women_id in the Women's table for the male table, so that the two tables are linked by setting up a table alone.
Examples of many-to-many understanding:
Each data in a man's table can correspond to multiple data in a woman's table, and each data in a woman's table can correspond to multiple data in a man's table.
MySQL has many-to-many tables