A hypothetical 1:M beer distributor example In this case we assume

A hypothetical 1:M beer distributor example
In this case we assume that we are looking at ONLY two tables (remember that there are generally
more) in a relational DB for a company that purchases beer from different suppliers and then sells the
beer to customers. A store like Pearl St. Beverage or the Beverage Warehouse would be a good
example… We also assume that our store gets a particular product from only ONE supplier. For example,
ABC company supplies all Harpoon products in the region.
Supplier Table
SupplierID
SupplierName
S1
ABC Company
S2
Supplier XYZ
S3
Super Supplier
S4
….
Jim’s Beverage Barn
ContactName
Charlotte Smith
Shelly Burke
Joe Jones
SupplierAddress
49 Gilbert St.
P.O. Box 456
70 Oxford St.
SupplierPhone
802-444-5555
768-909-5656
802-455-3322
Jim Smith
29 King’s Way
802-444-0987
SupplierCity
Burlington
Boston
South
Burlington
Burlington
…… (means that there are, or we can have, many more entities/records in this table)
Product Table
ProductID
Manufacturer
ProductName
PRO1
Harpoon
IPA
PRO2
Harpoon
Leviathan Imperial
IPA
PRO3
Long Trail
Pale Ale
PRO4
Long Trail
Long Trail Ale
PRO5
Dog Fish Head
60 Minute IPA
PRO6
Switchback
Ale
PRO7
Long Trail
Double Bag
Quantity/unit
ordered
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
4, 12 oz bottles / pack
6, 4 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
5 gallon keg (order by
the keg)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
UnitPrice
UnitsInStock
$15
10
$25
3
$16
12
$15
8
$22
3
$50
2
$20
2
….
…… (means that there are, or we can have, many more entities/records in this table)
For our purposes, each table MUST have a PRIMARY KEY (PK) field/attribute to uniquely identify each
entity in the table (our entities in the Product table are the individual products and our entities in the
Supplier table are the individual suppliers). In our case we can create a PK attribute for each table –
SupplierID as the PK in the Supplier table and ProductID as the PK in the Product table. I’m highlighting
the PK attribute in the Product table
Product Table
ProductID
Manufacturer
ProductName
PRO1
Harpoon
IPA
PRO2
Harpoon
Leviathan Imperial
IPA
PRO3
Long Trail
Pale Ale
PRO4
Long Trail
Long Trail Ale
PRO5
Dog Fish Head
60 Minute IPA
PRO6
Switchback
IPA
PRO7
Long Trail
Double Bag
Quantity/unit
ordered
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
4, 12 oz bottles / pack
6, 4 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
5 gallon keg (order by
the keg)
6, 12 oz bottles / pack
4, 6 packs / case
(order by case)
UnitPrice
UnitsInStock
$15
10
$25
3
$16
12
$15
8
$22
3
$50
2
$20
2
First the ERD that describes the relationship we are modeling is:
Supplier
Each Can
Supply
1
M
Product
Each is
Supplied by
How do we know this is the relationship?
There are 2 tables (Supplier and Product) with ONE relationship connecting the two tables.
 Read the TOP of the relationship from left to right  Each supplier can supply MANY products.
This means that each one of the suppliers can supply multiple products to our store.

Read the BOTTOM of the relationship from right to left  Each product is supplied by only ONE
supplier. This means that each individual product is only provided or supplied by one supplier. In
reality this could be different. For example if the suppliers could provide the same products and
we shopped around and bought the products from different suppliers depending on price,
availability, reliability, etc. we would need to model this as M:M.
So far our tables are not linked in any way. Just stop for a second and look back at the two tables. There
are not shared attributes that we can use to move from one table to the next. At this point, we have a
relationship shown in the ERD, but there is no logical relationship between the two tables. To create a
relationship we must have a common attribute in both tables – at least one of the fields must appear in
both tables so that there is a common or shared field. We call this “shared” or common attribute the
Foreign Key (FK). For our purposes the FK always goes on the MANY side of the relationship.
So according to our partial ERD, we need to create a FK in the Product table – that is, we need to repeat
one of the attributes in the Supplier table in the Product table. For our purposes, we will always use the
PK field from the ONE side as the FK on the MANY side. So looking at the attributes in both tables we
have:
Supplier
Each Can
Supply
1
SupplierID (PK)
SupplierName
ContactName
SupplierAddress
SupplierPhone
SupplierCity
M
Product
Each is
Supplied by
ProductID (PK)
Manufactuer
ProductName
Quantity/Unit Ordered
UnitPrice
UnitsInStock
SupplierID (FK to
Supplier table)
Discussion: Where did the SupplierID field come from and why is it now in the Product table?
Supplier Table
SupplierID
SupplierName
S1
ABC Company
S2
Supplier XYZ
S3
Super Supplier
ContactName
Charlotte Smith
Shelly Burke
Joe Jones
SupplierAddress
49 Gilbert St.
P.P. Box 456
70 Oxford St.
SupplierPhone
802-444-5555
768-909-5656
802-455-3322
S4
Jim Smith
29 King’s Way
802-444-0987
Jim’s Beverage Barn
Product Table
ProductID Manufacturer
ProductName
PRO1
Harpoon
IPA
PRO2
Harpoon
Leviathan
Imperial IPA
PRO3
Long Trail
Pale Ale
PRO4
Long Trail
Long Trail Ale
PRO5
Dog Fish Head
60 Minute IPA
PRO6
Switchback
IPA
PRO7
Long Trail
Double Bag
INTERPRETATION and discussion
Quantity/unit
ordered
6, 12 oz bottles /
pack
4, 6 packs / case
(order by case)
4, 12 oz bottles /
pack
6, 4 packs / case
(order by case)
6, 12 oz bottles /
pack
4, 6 packs / case
(order by case)
6, 12 oz bottles /
pack
4, 6 packs / case
(order by case)
6, 12 oz bottles /
pack
4, 6 packs / case
(order by case)
5 gallon keg (order
by the keg)
6, 12 oz bottles /
pack
4, 6 packs / case
(order by case)
UnitPrice
UnitsInStock
SupplierCity
Burlington
Boston
South
Burlington
Burlington
SupplierID
$15
10
S1
$25
3
S1
$16
12
S2
$15
8
S2
$22
3
S3
$50
2
S3
$20
2
S2