Skip to content

Commit 92ae533

Browse files
committed
many to many and one to many diagrams
1 parent 22f50c1 commit 92ae533

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed
99.4 KB
Loading
28.8 KB
Loading

module2-database-technologies/r2.1-understanding-relational-database-structure/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ since one customer has many orders. It should be noted that the foreign key goes
77
on the side that is "many". In the example above, note that the `customer_id`
88
key is located on the `Order` table.
99

10+
![One to many relationship](../assets/one-to-many.png)
11+
1012
For a many-to-many relationship, consider students and courses at a university.
1113
A student can take many courses; a course also has many students. Many-to-many
1214
relationships are [expressed slightly
1315
differently](https://dzone.com/articles/how-to-handle-a-many-to-many-relationship-in-datab) than using a single foreign key.
1416

17+
To express a many-to-many relationship between two tables, we create a third
18+
table that contains the foreign keys of the two tables being connected. For
19+
example, the diagram below connects classes and students together through a
20+
table called `Enrollments`. Each row in `Enrollments` represents one class that
21+
one student is taking; there can be multiple such entries in the table.
22+
23+
![Many to many relationship](../assets/many-to-many.png)
24+
1525
See this [StackOverflow
1626
question](https://stackoverflow.com/questions/4601703/difference-between-one-to-many-and-many-to-one-relationship)
1727
for more details.

0 commit comments

Comments
 (0)