ERD Cardinality
OOD Inge Powell
ERD Cardinality
 When

we show relationships between
tables we need to show the cardinality.
 Depending on the data we are storing
there are several options to choose
from.
 If using Visio to create a diagram, it
takes its initial value from the database
store.
Erd Cardinality
 The

cardinality relationship is shown with
lines between two entities to indicate a
relationship.
Entity A

 This

Entity B

line denotes that there is a
relationship between the entities.
ERD Cardinality
 The

ENDS of these lines denote the cardinality
to that entity.
Entity A

 This

Entity B

is a ‘One to One’ relationship.
 This means that Entity A will relate to only one
of Entity B.
 And Entity B will relate to only one of Entity A
Erd Cardinality
 Here

is an example..
Bus

Driver

 One

Driver drives just one Bus.
 One Bus has just one Driver.
 The records might be held like this:
Bus
Bus

PK BusID
PK BusID
Colour
Colour
NoOfSeats
NoOfSeats
FK DriverID
FK DriverID

Driver
Driver

PK DriverID
PK DriverID
Name
Name
Points
Points
FK BusID
FK BusID
ERD Cardinality
 The

use of ‘Crows Feet’.
Entity A

 This

Entity B

is a ‘One to Many’ relationship.
 This means that Entity A will relate to many of
Entity B.
 And Entity B will relate to only one of Entity A.
Erd Cardinality
 Here

is an example.

Customer

Order

 One

Customer may have many orders.
 One Order is for just one Customer.
 The records might be held like this:
Customer
Customer

PK CustID
PK CustID
Name
Name
Address
Address

TelNo
TelNo

Order
Order

PK OrderNo
PK OrderNo
Date
Date
FK CustID
FK CustID
ERD Cardinality
 The

use of ‘Crows Feet’.

Entity A

Entity B

 This

is a ‘Many to One’ relationship.
 This means that Entity A will relate to only one
of Entity B.
 And Entity B will relate to many of Entity A.


(We still tend to refer to as a one to many, just the
other way round from B to A)
Erd Cardinality
 Here

is an example.
Product

Supplier

 One

Product will have just one Supplier.
 One Supplier will supply many Products.
 The records might be held like this:
Product
Product
PK ProdID
PK ProdID
PName
PName
Price
Price

Supplier
Supplier
PK SuppID
PK SuppID
Name
Name
Address
Address
TelNo
TelNo
ERD Cardinality
 The

use of ‘Crows Feet’.
Entity A

 This

Entity B

is a ‘Many to Many’ relationship.
 This means that Entity A will relate to many of
Entity B.
 And Entity B will relate to many of Entity A.
ERD Cardinality
 Many

to Many - This can cause problems with
data, as we can’t pinpoint the link.
Entity A

Entity B

 Imagine

this, a Lender can borrow many
Books. But a Book can be borrowed by more
than one Lender.
Lender

Book
ERD Cardinality
 How

do we know who has each individual
book?
Lender

Book

 Also

when we look at the data, how will we
store this?
Lender
Lender

PK LenderID
PK LenderID
Name
Name
Address
Address
FK BookID
FK BookID
FK BookID
FK BookID
FK BookID

Book
Book

PK BookID
PK BookID

FK
FK

Title
Title
Author
Author

LenderID
LenderID
ERD Cardinality
 To

manage the many to many relationship, the
data would need to keep growing.

 This

still causes problems,
 Who has the book now?
 This
 We

is silly!!

can resolve this
 By adding a link table.

Book
Book

PK BookID
PK BookID
Title
Title
Author
Author
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
ERD Cardinality
 To

resolve a many to many relationship.
Entity A

 We

Entity B

resolve it by adding a link table.

Entity A

 This

Entity C

Entity B

means we now have two manageable
one to many relationships instead.
ERD Cardinality
 The

resolved many to many relationship.

Lender

LendRecord

Book

 One

lender can have several LendRecords
 One LendRecord is for just one Lender
 One

Book can have several LendRecords
 One LendRecord is for just one Book
ERD Cardinality
 Here

is the resolved example.

Lender

LendRecord

Book

 The

data for this system might look something
like this:
Lender
Lender

PK LenderID
PK LenderID
Name
Name
Address
Address

Book
Book
LendRecor
LendRecor
d
d
PK RecordID
PK RecordID
FK BookID
FK BookID
FK LenderID
FK LenderID

PK BookID
PK BookID
Title
Title
Author
Author
ERD Cardinality
 The

LendRecord record could be deleted
when the book is returned.
Lender

 Or

LendRecord

Book

fields added to identify the current loan.

Lender
Lender

PK LenderID
PK LenderID
Name
Name
Address
Address

Book
Book
LendRecor
LendRecor
d
d
PK RecordID
PK RecordID
FK BookID
FK BookID
FK LenderID
FK LenderID
OnLoanYN
OnLoanYN
Date

PK BookID
PK BookID
Title
Title
Author
Author

Erd cardinality

  • 1.
  • 2.
    ERD Cardinality  When weshow relationships between tables we need to show the cardinality.  Depending on the data we are storing there are several options to choose from.  If using Visio to create a diagram, it takes its initial value from the database store.
  • 3.
    Erd Cardinality  The cardinalityrelationship is shown with lines between two entities to indicate a relationship. Entity A  This Entity B line denotes that there is a relationship between the entities.
  • 4.
    ERD Cardinality  The ENDSof these lines denote the cardinality to that entity. Entity A  This Entity B is a ‘One to One’ relationship.  This means that Entity A will relate to only one of Entity B.  And Entity B will relate to only one of Entity A
  • 5.
    Erd Cardinality  Here isan example.. Bus Driver  One Driver drives just one Bus.  One Bus has just one Driver.  The records might be held like this: Bus Bus PK BusID PK BusID Colour Colour NoOfSeats NoOfSeats FK DriverID FK DriverID Driver Driver PK DriverID PK DriverID Name Name Points Points FK BusID FK BusID
  • 6.
    ERD Cardinality  The useof ‘Crows Feet’. Entity A  This Entity B is a ‘One to Many’ relationship.  This means that Entity A will relate to many of Entity B.  And Entity B will relate to only one of Entity A.
  • 7.
    Erd Cardinality  Here isan example. Customer Order  One Customer may have many orders.  One Order is for just one Customer.  The records might be held like this: Customer Customer PK CustID PK CustID Name Name Address Address TelNo TelNo Order Order PK OrderNo PK OrderNo Date Date FK CustID FK CustID
  • 8.
    ERD Cardinality  The useof ‘Crows Feet’. Entity A Entity B  This is a ‘Many to One’ relationship.  This means that Entity A will relate to only one of Entity B.  And Entity B will relate to many of Entity A.  (We still tend to refer to as a one to many, just the other way round from B to A)
  • 9.
    Erd Cardinality  Here isan example. Product Supplier  One Product will have just one Supplier.  One Supplier will supply many Products.  The records might be held like this: Product Product PK ProdID PK ProdID PName PName Price Price Supplier Supplier PK SuppID PK SuppID Name Name Address Address TelNo TelNo
  • 10.
    ERD Cardinality  The useof ‘Crows Feet’. Entity A  This Entity B is a ‘Many to Many’ relationship.  This means that Entity A will relate to many of Entity B.  And Entity B will relate to many of Entity A.
  • 11.
    ERD Cardinality  Many toMany - This can cause problems with data, as we can’t pinpoint the link. Entity A Entity B  Imagine this, a Lender can borrow many Books. But a Book can be borrowed by more than one Lender. Lender Book
  • 12.
    ERD Cardinality  How dowe know who has each individual book? Lender Book  Also when we look at the data, how will we store this? Lender Lender PK LenderID PK LenderID Name Name Address Address FK BookID FK BookID FK BookID FK BookID FK BookID Book Book PK BookID PK BookID FK FK Title Title Author Author LenderID LenderID
  • 13.
    ERD Cardinality  To managethe many to many relationship, the data would need to keep growing.  This still causes problems,  Who has the book now?  This  We is silly!! can resolve this  By adding a link table. Book Book PK BookID PK BookID Title Title Author Author FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID FK LenderID
  • 14.
    ERD Cardinality  To resolvea many to many relationship. Entity A  We Entity B resolve it by adding a link table. Entity A  This Entity C Entity B means we now have two manageable one to many relationships instead.
  • 15.
    ERD Cardinality  The resolvedmany to many relationship. Lender LendRecord Book  One lender can have several LendRecords  One LendRecord is for just one Lender  One Book can have several LendRecords  One LendRecord is for just one Book
  • 16.
    ERD Cardinality  Here isthe resolved example. Lender LendRecord Book  The data for this system might look something like this: Lender Lender PK LenderID PK LenderID Name Name Address Address Book Book LendRecor LendRecor d d PK RecordID PK RecordID FK BookID FK BookID FK LenderID FK LenderID PK BookID PK BookID Title Title Author Author
  • 17.
    ERD Cardinality  The LendRecordrecord could be deleted when the book is returned. Lender  Or LendRecord Book fields added to identify the current loan. Lender Lender PK LenderID PK LenderID Name Name Address Address Book Book LendRecor LendRecor d d PK RecordID PK RecordID FK BookID FK BookID FK LenderID FK LenderID OnLoanYN OnLoanYN Date PK BookID PK BookID Title Title Author Author