One to one, one to many, many to many

One-to-one relationship: there are two tables A, a field in the BA table is the primary key of the B table, then a record of the A table can only correspond to a record of the B table (because it is the primary key, and the only) record, this is A One-to-one mapping from table to table B
One-to-many relationship: There are two tables A, one field in the BA table is the primary key of the B table, then a record of the B table can theoretically correspond to multiple records of the A table (A field may have many fields in many rows Point to the primary key of table B) This is a one-to-many mapping of table B to table A.
Summary: One table can only find one record in another table, then it is a one-to-one mapping.
     One table can find multiple records in another table, then it is a one-to-many mapping.
 
Many-to-many: There are two databases, and the third data table indicates the association. The associated tables point to the primary keys of the other two tables. For example, table A has three users with ids 1, 2, 3, and table B has three users with ids 11.12.13 in the middle table
A表Id     B表id 
   1            11
   1            12
   1             13
   2            12 
   2             13
   3             11
You can query many users in a table to become a many-to-many mapping. One A can map many B, one B can map many A

Guess you like

Origin www.cnblogs.com/Vinlen/p/12749988.html