File tree Expand file tree Collapse file tree 3 files changed +10
-0
lines changed
module2-database-technologies
r2.1-understanding-relational-database-structure Expand file tree Collapse file tree 3 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -7,11 +7,21 @@ since one customer has many orders. It should be noted that the foreign key goes
7
7
on the side that is "many". In the example above, note that the ` customer_id `
8
8
key is located on the ` Order ` table.
9
9
10
+ ![ One to many relationship] ( ../assets/one-to-many.png )
11
+
10
12
For a many-to-many relationship, consider students and courses at a university.
11
13
A student can take many courses; a course also has many students. Many-to-many
12
14
relationships are [ expressed slightly
13
15
differently] ( https://dzone.com/articles/how-to-handle-a-many-to-many-relationship-in-datab ) than using a single foreign key.
14
16
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
+
15
25
See this [ StackOverflow
16
26
question] ( https://stackoverflow.com/questions/4601703/difference-between-one-to-many-and-many-to-one-relationship )
17
27
for more details.
You can’t perform that action at this time.
0 commit comments