Erd cardinality

IngePowell 20,828 views 17 slides Feb 02, 2014
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

No description available for this slideshow.


Slide Content

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.
This line denotes that there is a
relationship between the entities.
Entity A Entity B

ERD Cardinality
The ENDS of these lines denote the cardinality
to that entity.
This 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
Entity A Entity B

Erd Cardinality
Here is an example..
One Driver drives just one Bus.
One Bus has just one Driver.
The records might be held like this:
Bus Driver
Bus
PK BusID
Colour
NoOfSeats
FK DriverID
Bus
PK BusID
Colour
NoOfSeats
FK DriverID
Driver
PK DriverID
Name
Points
FK BusID
Driver
PK DriverID
Name
Points
FK BusID

ERD Cardinality
The use of ‘Crows Feet’.
This 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.
Entity A Entity B

Erd Cardinality
Here is an example.
One Customer may have many orders.
One Order is for just one Customer.
The records might be held like this:
Customer Order
Customer
PK CustID
Name
Address
TelNo
Customer
PK CustID
Name
Address
TelNo
Order
PK OrderNo
Date
FK CustID
Order
PK OrderNo
Date
FK CustID

ERD Cardinality
The use of ‘Crows Feet’.
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)
Entity A Entity B

Product
PK ProdID


PName
Price
FK
SuppID
Product
PK ProdID


PName
Price
FK
SuppID
Erd Cardinality
Here is an example.
One Product will have just one Supplier.
One Supplier will supply many Products.
The records might be held like this:
Product Supplier
Supplier
PK SuppID
Name
Address
TelNo
Supplier
PK SuppID
Name
Address
TelNo
Product
PK ProdID


PName
Price
FK
SuppID
Product
PK ProdID


PName
Price
FK
SuppID
Product
PK ProdID


PName
Price
FK
SuppID
Product
PK ProdID


PName
Price
FK
SuppID
Supplier
PK SuppID
Name
Address
TelNo
Supplier
PK SuppID
Name
Address
TelNo
Product
PK ProdID


PName
Price
FK
SuppID
Product
PK ProdID


PName
Price
FK
SuppID

ERD Cardinality
The use of ‘Crows Feet’.
This 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.
Entity A Entity B

ERD Cardinality
Many to Many - This can cause problems with
data, as we can’t pinpoint the link.
Imagine this, a Lender can borrow many
Books. But a Book can be borrowed by more
than one Lender.
Entity A Entity B
Lender Book

Book
PK BookID

Title
Author
FK
LenderID
FK
LenderID
FK
LenderID
FK LenderID
Book
PK BookID

Title
Author
FK
LenderID
FK
LenderID
FK
LenderID
FK LenderID
ERD Cardinality
How do we know who has each individual
book?
Also when we look at the data, how will we
store this?
Lender Book
Lender
PK LenderID

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

Name
Address
FK BookID
FK BookID
FK BookID
FK BookID

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 is silly!!
We can resolve this
By adding a link table.
Book
PK BookID

Title
Author
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
FK LenderID
Book
PK BookID

Title
Author
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.
We resolve it by adding a link table.
This means we now have two manageable
one to many relationships instead.
Entity A Entity BEntity C
Entity A Entity B

ERD Cardinality
The resolved many to many relationship.
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
Lender BookLendRecord

ERD Cardinality
Here is the resolved example.
The data for this system might look something
like this:
Lender BookLendRecord
Book
PK BookID

Title
Author
Book
PK BookID

Title
Author
LendRecor
d
PK RecordID
FK BookID

FK LenderID

LendRecor
d
PK RecordID
FK BookID

FK LenderID

Lender
PK LenderID

Name
Address
Lender
PK LenderID

Name
Address

ERD Cardinality
The LendRecord record could be deleted
when the book is returned.
Or fields added to identify the current loan.
Lender BookLendRecord
Book
PK BookID

Title
Author
Book
PK BookID

Title
Author
LendRecor
d
PK RecordID
FK BookID

FK LenderID

OnLoanYN
Date

LendRecor
d
PK RecordID
FK BookID

FK LenderID

OnLoanYN
Date

Lender
PK LenderID

Name
Address
Lender
PK LenderID

Name
Address
Tags