Entity Relationship DiagramsLearning objective11.2.2.2 create entity-relationship diagrams (ERD) An entity-relationship diagram (ERD) shows the relationships between entities in a system and how they connect. 1. Entities and relationshipsThe Coding club organises workshops for students. We want to model which students attend which workshops. EntityA type of person, object or concept about which the system stores information. Examples: Students, Workshops. RelationshipAn association between entities. A verb often helps us describe it. Example: Students attend Workshops. Draw each entity as a named rectangle. Draw a line between related entities. Add one or many at each end, using the rules of the scenario. Ask two questions: “How many workshops can one student attend?” and “How many students can one workshop have?” 2. A simple notation: one and manyWe use a simplified Crow’s Foot notation. A single bar means one. A three-pronged foot means many. The marks show only the maximum number: one or many. The mark next to an entity counts that entity. For example, many next to Workshops means that one student can attend many workshops. M and N both mean many. They can stand for different numbers. “Many” means that more than one is allowed; it does not mean that every student currently attends several workshops.
On a small screen, scroll a diagram horizontally to see it in full. 3. Coding club: three relationshipsA. Students attend workshops — M:N
There is many at both ends, so this is a many-to-many relationship. B. Mentors lead workshops — 1:MFor this model, each workshop is led by one mentor.
Read from Mentors to Workshops: one-to-many. Read in the opposite direction: many-to-one. This is the same relationship viewed from the other end. C. Students have club cards — 1:1For this model, we consider each student’s current club card.
There is one at both ends, so this is a one-to-one relationship. Use the stated rules. If workshops could have several mentors, the Mentors–Workshops relationship would change to M:N. ERD builder (online)4. Other examplesShanyrak teams and studentsIn this model, a Shanyrak team includes many students, and each student belongs to one team. This is 1:M from teams to students. Library borrowing over timeA member can borrow many physical book copies over time. The same copy can be borrowed by different members at different times. For the whole borrowing history, the relationship is M:N. State the time frame. This diagram describes borrowing over time, rather than who holds a copy at this moment. 5. Relationship laboratoryChange the proposed rules. The diagram shows only entities and one/many marks. These controls do not change the examples above. Interactive checks are loading. If this message remains, use the explanations and model answers. Current diagram: many-to-many (M:N). Many-to-many (M:N). One student can attend many workshops, and one workshop can have many students. Explain: Which mark counts students? Which mark counts workshops? Read each new diagram in both directions. ExercisesExercise 1. LearningAppsComplete the original true/false activity. Exercise 2. LearningAppsIdentify the entities in the given statements. Completed: 0 / 6 checked activities (Exercises 3–8). Practice checks run on this page. Progress resets when you reload. LearningApps has its own checks. Exercise 3. Identify the entitiesThe Coding club wants to show which students attend which workshops. Select the two entities.
Explanation / model answerStudents and Workshops are the entities. Attend describes the relationship between them. Exercise 4. Choose the relationship typeUse the rules given in each scenario.
Explanation / model answerStudents–Workshops: M:N. Mentors–Workshops: 1:M. Students–Club cards: 1:1. Check the rule in both directions before choosing. Exercise 5. Read both directionsUse the Mentors–Workshops diagram from the Coding club example.
Explanation / model answerOne mentor can lead many workshops; one workshop has one mentor. The mark next to Workshops counts workshops. The mark next to Mentors counts mentors. Exercise 6. Change a business ruleThe club now keeps all cards issued over time, including replaced cards. One student can have several cards in this history; each card belongs to one student.
Explanation / model answerThe relationship becomes Students 1:M Club cards. Put one next to Students and many next to Club cards. The old rule was about one current card; the new rule includes all cards issued over time. Exercise 7. Set the time frameA library member can borrow several physical book copies. For this model, each borrowed copy is held by one member at a time.
Explanation / model answerCurrent borrowing: 1:M from Members to Book copies. Borrowing history: M:N. Over time, a member can borrow several copies, and a copy can be borrowed by several different members. State the time frame before drawing the diagram. Exercise 8. Draw an ERDA Shanyrak team can take part in several activities. Each activity can include several teams. Draw the ERD on paper, then check your decisions below.
Explanation / model answerUse two entity rectangles, Teams and Activities, with many at both ends of the connector: M:N. Read it aloud: “One team can take part in many activities. One activity can include many teams.” The automatic check assesses your choices; compare your drawing with this model yourself. Explain your diagram
Model explanations1. One student can attend many workshops. One workshop can have many students. This is a many-to-many relationship. 2. A mentor can lead many workshops, and a workshop can now have many mentors. The relationship changes from one-to-many to many-to-many. 3. Draw two rectangles labelled Authors and Books. Put many at both ends of the connecting line: M:N. Check your ERD: name the entities, connect related entities, add one or many at each end, and explain both directions using the scenario rules. Practice: Relational databases. The Coding club, card, team and library scenarios are illustrative models. Follow the rules stated for each example. Play: ERD Tetris — Catch the RelationshipOpen the game in a separate window Read the falling description and choose the matching relationship: 1:1, 1:M or M:N. Click inside the game before using keys 1, 2 and 3. Open the game in a separate window You can play here or use the link above for a larger view. | |||||||||||||||||||
|
| |||||||||||||||||||
| Просмотров: 12284 | Комментарии: 1 | | | |||||||||||||||||||
| Всего комментариев: 1 | |
|
| |