Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 3 Tables 2 Shipment ID Shipment Sent Shipment Received 40019/1/20119/9/2011 40029/3/20119/23/2011 40039/22/20119/29/2011 400410/2/201110/15/2011 400510/21/2011 Material ID CategoryHazardous 1ElectronicsFalse 2CompositesFalse 3MachineryFalse 4SolventsTrue 5PetrochemicalsTrue ShipmentItems Shipment ID Lineno Material ID 400113 24 35 400211 22 400312 24 33 400413 400515 22 31 41 52

3 Model Extended to include Suppliers 3

4 4 Tables (to be used for queries) 4 Material ID CategoryHazardous 1ElectronicsFalse 2CompositesFalse 3MachineryFalse 4SolventsTrue 5PetrochemicalsTrue ShipmentItems Shipment ID Lineno Material ID 400113 24 35 400211 22 400312 24 33 400413 400515 22 31 41 52 Shipment ID Shipment Sent Shipment Received Supplier ID 40019/1/20119/9/20113 40029/3/20119/23/20115 40039/22/20119/29/20112 400410/2/201110/15/20112 400510/21/20114 Supplier ID Supplier Name CityState Delivery EffRank Cost EffRank 1VanguardNew OrleansLouisiana23 2SmithfieldHoustonTexas14 3BlackstoneJacksonvilleFlorida51 4CommodoreNorfolkVirginia45 5LakeshoresLong BeachCalifornia32

5 Querying across 3 tables List the material categories, the shipment ID, Line #, and date received for all items received on 9/9/2011 SELECT Category, Shipment.ShipmentID, Lineno, ShipmentReceived FROM Shipment, ShipmentItems, Material Where Shipment.ShipmentID = ShipmentItems.ShipmentID AND ShipmentItems.MaterialID = Material.MaterialID AND ShipmentReceived = #9/9/2011#; 5 Category Shipment ID Lineno Shipment Received Machinery400119/9/2011 Solvents400129/9/2011 Petrochemicals400139/9/2011

6 Model Further Extended to include Employees & Clients 6 If you can SQL using 2 or 3 tables – you have the skills to run SQL using 1,000 tables

7 All Tables 7 Material ID CategoryHazardous 1ElectronicsFalse 2CompositesFalse 3MachineryFalse 4SolventsTrue 5PetrochemicalsTrue ShipmentItems Shipment ID Lineno Material ID 400113 24 35 400211 22 400312 24 33 400413 400515 22 31 41 52 Shipment ID Shipment Sent Shipment Received Supplier ID Client ID 40019/1/20119/9/201136 40029/3/20119/23/2011512 40039/22/20119/29/201129 400410/2/201110/15/201123 400510/21/201147 Supplier ID Supplier Name CityState Delivery EffRank Cost EffRank 1VanguardNew OrleansLouisiana23 2SmithfieldHoustonTexas14 3BlackstoneJacksonvilleFlorida51 4CommodoreNorfolkVirginia45 5LakeshoresLong BeachCalifornia32 Client ID Client Name Client Services Client City Client State Client Revenue Emp ID 1BK AssociatesCommercialPortlandOregon$210,000.002 2BlalocIndustrialKansas CityMissouri$330,000.002 3Bankton ElectricGovernmentNew York $210,000.003 4BickIndustrialRaleighNorth Carolina$550,000.001 5TX ElectricGovernmentHoustonTexas$160,000.003 6CrowCommercialDallasTexas$270,000.002 7GRBIndustrialAtlantaGeorgia$180,000.001 8H&PIndustrialDenverColorado$90,000.002 9LB&BIndustrialBostonMassachusetts$211,000.003 10CongroIndustrialAtlantaGeorgia$122,000.003 11Moss EnterprisesCommercialPhoenixArizona$33,000.001 12RubyIndustrialSan AntonioTexas$344,000.003 13Silver IndustriesIndustrialOmahaNebraska$218,000.002 14TPHCommercialAnnaheimCalifornia$166,000.001 Employee Emp ID Emp first Name Emp last name Emp status Emp Rate 1DanPiercefull time$120.00 2SeanSmithfull time$85.00 3LauraJohnsonfull time$85.00 4MikeLucasfull time$55.00 5LarryWilsonfull time$55.00 6KeithEthridgepart time$25.00


Download ppt "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."

Similar presentations


Ads by Google