One-to-Many+and+Many-to-Many+Relationships

One-to-Many+and+Many-to-Many+Relationships - This is...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
One-to-Many and Many-to-Many Relationships One-to-Many Relationships At the Night School, students can only sign up for one course. However, each course has many students in it. Therefore, there is a one-to-many relationship between the tables. To implement this relationship, we first add a CourseID field to the NightSchoolStudents table. This will be a foreign key . We then create the relationship by dragging CourseID from one table to the other in the relationship diagram:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
That’s all it takes to create a one-to-many relationship.
Background image of page 2
Many-to-many relationships At a nearby day school, each course still has many students, but here each student can sign up for several classes. This is a many-to-many relationship. To implement the relationship, we create a new table whose primary key is made up of the combination of the primary keys in the two entities tables:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: This is referred to as an intersection table. We then create one-to-many relationships between each entity tables primary key and the corresponding field in the intersection table. The intersection table includes combinations of StudentID and CourseID. Each row indicates that a particular student is in a particular course: Frequently, there are attributes which belong in an intersection table. In this case, an attribute which is not an attribute of just a student, nor of just a course, but of the combination, is the students grade. A particular student may get an A in one course and a B in another, and the instructor may give a wide range of grades in a particular course. However, each student only gets one grade in a given course. Therefore, the grade belongs in the intersection table:...
View Full Document

Page1 / 4

One-to-Many+and+Many-to-Many+Relationships - This is...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online