Many-to-many (M:M) relationship • M:M Concept: A Shipment can contain many types of Materials and a type of Material can be sent in many different shipments • M:M is converted into two 1:M relationships - Intersection entity/table is created • The intersection table must have two foreign keys • One for each of the entities in the m:m relationship • A foreign key can also be part of the primary key for the intersection table 1
7
Embed
Many-to-many (M:M) relationship M:M Concept: A Shipment can contain many types of Materials and a type of Material can be sent in many different shipments.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Many-to-many (M:M) relationship• M:M Concept: A Shipment can contain many types of Materials
and a type of Material can be sent in many different shipments• M:M is converted into two 1:M relationships - Intersection
entity/table is created• The intersection table must have two foreign keys
• One for each of the entities in the m:m relationship• A foreign key can also be part of the primary key for the
intersection table
1
3 Tables
2
ShipmentShipment
IDShipment
SentShipmentReceived
4001 9/1/2011 9/9/2011
4002 9/3/2011 9/23/2011
4003 9/22/2011 9/29/2011
4004 10/2/2011 10/15/2011
4005 10/21/2011
MaterialMaterial
IDCategory Hazardous
1 Electronics False
2 Composites False
3 Machinery False
4 Solvents True
5 Petrochemicals True
ShipmentItemsShipment
IDLineno
MaterialID
4001 1 3
4001 2 4
4001 3 5
4002 1 1
4002 2 2
4003 1 2
4003 2 4
4003 3 3
4004 1 3
4005 1 5
4005 2 2
4005 3 1
4005 4 1
4005 5 2
Model Extended to include Suppliers
3
4 Tables (to be used for queries)
4
MaterialMaterial
IDCategory Hazardous
1 Electronics False
2 Composites False
3 Machinery False
4 Solvents True
5 Petrochemicals True
ShipmentItemsShipment
IDLineno
MaterialID
4001 1 3
4001 2 4
4001 3 5
4002 1 1
4002 2 2
4003 1 2
4003 2 4
4003 3 3
4004 1 3
4005 1 5
4005 2 2
4005 3 1
4005 4 1
4005 5 2
ShipmentShipment
IDShipment
SentShipmentReceived
SupplierID
4001 9/1/2011 9/9/2011 3
4002 9/3/2011 9/23/2011 5
4003 9/22/2011 9/29/2011 2
4004 10/2/2011 10/15/2011 2
4005 10/21/2011 4
SupplierSupplier
IDSupplier
NameCity State
DeliveryEffRank
CostEffRank
1 Vanguard New Orleans Louisiana 2 3
2 Smithfield Houston Texas 1 4
3 Blackstone Jacksonville Florida 5 1
4 Commodore Norfolk Virginia 4 5
5 Lakeshores Long Beach California 3 2
Querying across 3 tables
List the material categories, the shipment ID, Line #, and date received for all items received on 9/9/2011