Upload
inge-powell
View
487
Download
8
Embed Size (px)
DESCRIPTION
Citation preview
ERD Optionality
OOD Inge Powell
ERD Optionality
When we show relationships between tables as well as the cardinality we also need to show the optionality.
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 Optionality
The cardinality shows what type of relation ship, (One to One or One to Many etc)
But is does not state whether this is a mandatory or optional relationship.
A Mandatory relationship is where there must be at least one matching record in each entity.
An Optional relationship is where there may or may not be a matching record in each entity.
ERD Optionality
The relationship is shown with a connecting line between the entities.
The cardinality is shown by the use of crows feet or lines.
But is does not state whether this is a mandatory or optional relationship?
Entity A Entity B
Entity A Entity B
ERD Optionality
The optionality is shown inside the cardinality.
Entity A Entity B
The optionality is shown inside the cardinality.
Cardinality
Optionality
ERD Optionality
A Mandatory relationship is shown with a vertical line next to the cardinality. (Must be at least one Entity A)
An Optional relationship is shown with a hollow circle next to the cardinality (There maybe 0 to many of Entity B
Entity A
Entity B
ERD Optionality
There are several types. Consider the optionality of the next few examples when combined with cardinality.
At least one entity. One and only one entity.
None or one entity. May be none or one or more than one entity.
Entity Entity
Entity Entity
ERD Optionality
Here are some Mandatory examples..
One Customer has made at least one order.
One Order is for Only One Customer
Customer Order
Customer Order
ERD Optionality
Here are some Optional examples..
One Protected Species record may be for none, one or many kept reptiles.
One Reptile may or may not have a protected species record.
Protected Species
Reptile
Protected Species
Reptile
ERD Optionality
Here are some Mixed examples.
One Category may have none, one or many Products.
One Product will have one and only one Category.
Category Product
Category Product
ERD Optionality
Very rarely there is a optional mandatory relationship. This is usually where there are several tables
concerned. This is a mutually exclusive relationship.
A Bus will have one or more MOT records. A Minibus will have one or more MOT records. An MOT record MUST be for either a bus or a
minibus. It must be for at least One of the entities.
Bus
MOT
Minibus
ERD Optionality
Scenario: A small hire car firm has several cars. The company ensures that the cars they
buy have an initial service. Each car is serviced regularly.Records are kept of each car and each
service.
Car Service
ERD Optionality
In the scenario, there will always be at least one service record for a car.
If a service has been recorded then it must have a matching car record.
This is a Mandatory relationship.
Car Service
Will have at least one
Will have a matching car
Erd Optionality
We add in the optionality.
One Car has one or more Service records. One Service record is for only one Car record. The records might be held like this:
Car Service
CarPK CarID Make Model EngineCC
CarPK CarID Make Model EngineCC
ServicePK ServiceID Date GarageFK CarID
ServicePK ServiceID Date GarageFK CarID
ERD Optionality
Look at all of your relationships in turn.
This is a ‘One to Many’ relationship. Ask yourself, Does Entity A, HAVE to have an
Entity B? If it does, then place a single vertical line next
to the crows feet of Entity B. If it does not, then place a circle by the crows
feet of Entity B.
Entity A Entity B
ERD Optionality
Entity A DOES have to have at least 1 Entity B
Entity A does NOT have to have an Entity B.
Entity A Entity B
Entity A Entity B
ERD Optionality
Lets say you decided that it could be optional. Now look at the reverse relationship.
Ask yourself, Does Entity B, HAVE to have an Entity A?
If it does, then place another vertical line next to the cardinality of Entity A.
If it does not, then place a circle by Entity A.
Entity A Entity B
ERD Optionality
Entity B DOES have to have an Entity A
Entity B does NOT have to have an Entity A.
Entity A Entity B
Entity A Entity B
Erd Optionality
Visio will pick up the relationship types from the database structure.
If it is not showing the optionality correctly, then the issue is in the database relationships.
A One To Many relationship will give an optional link as default.
You must set Referential Integrity to true and correctly set the Join type.
Customer Order????