ER Diagrams   «Prev  Next»

Resolving many-to-many Relationships - Exercise

Objective: Convert a many-to-many relationship into two "one-to-many" relationships.

Exercise Scoring

This exercise is worth a total of 30 points. You will receive up to 10 points for correctly creating each attribute of the composite entity as described below.
  • Background and Overview
    In the preceding lesson, you learned that many-to-many relationships are resolved by breaking down each M:N relationship into two 1:N relationships. This is achieved by creating a composite entity whose only function is to represent the link between the other two entities. You also learned that the composite entity has no key attribute of its own; rather, it accepts the key attributes from the other two entities to form a composite key attribute.
  • Instructions
    The Stories on CD case study has one many-to-many relationship: the ORDER:CD relationship. Your task is to resolve the ORDER:CD relationship. The two entities are illustrated below, complete with the attributes you will need to complete this exercise.

Two Entities ORDER and CD
The database diagram shows two tables: `ORDER` and `CD`. Below is a detailed analysis of each table's attributes and the inferred relationship between them:
  1. ORDER Table Attributes:
    • OrderNo – Likely the primary key of the ORDER table; uniquely identifies each order.
    • CustID – Identifies the customer placing the order (foreign key to a CUSTOMER table not shown).
    • OrderDate – The date the order was placed.
    • Quantity – Number of items ordered.
    • LineCost – Total cost for the line item (Quantity × UnitPrice).
    • ShipDate – The date the order was shipped.
  2. CD Table Attributes:
    • CDNo – Likely the primary key of the CD table; uniquely identifies each CD.
    • CDTitle – Title of the CD.
    • DistID – Distributor ID (foreign key to a DISTRIBUTOR table not shown).
    • RetailPrice – Selling price of the CD.
    • AgeGroup – Target age group for the CD.
    • Description – Additional details or content description of the CD.
Inferred Relationship:
There is no foreign key shown directly linking `ORDER` and `CD`, so based on standard modeling practice:
  • A many-to-many relationship likely exists between `ORDER` and `CD`.
    • A single order can include multiple CDs.
    • A single CD can appear in multiple orders.
Implication:
To represent this many-to-many relationship in a normalized relational model, a junction (or associative) table is needed — often called `ORDER_DETAIL` or similar — that includes:
  • `OrderNo` (foreign key to `ORDER`)
  • `CDNo` (foreign key to `CD`)
  • Possibly `Quantity`, `LineCost`, etc. (if not already in `ORDER`)
Summary:
Table Attributes
ORDER `OrderNo`, `CustID`, `OrderDate`, `Quantity`, `LineCost`, `ShipDate`
CD `CDNo`, `CDTitle`, `DistID`, `RetailPrice`, `AgeGroup`, `Description`

Inferred Relationship:
  • ORDER ↔️ (many-to-many) ↔️ CD
  • Requires an intermediate table (not shown) to fully represent this relationship.

Two Entities ORDER and CD

Please name the composite entity you create LINE ITEM. Your answer should be in the following format:
ORDER
attribute
attribute
etc.

LINE ITEM
attribute
attribute
etc.

CD
attribute
attribute
etc.

Hints

When a composite entity is created to link two other entities, it sometimes makes sense to move some non-key attributes out of the other two entities and into the composite entity. Keep this in mind when you populate the composite entity with attributes.
  • Submitting your exercise
    Type or paste your answers into the text box below, then click Submit to submit your result and view a results page.