erd intro v01 - securesecure.com.sg/courses/pis/grab/s02_2011_05_25/s02... ·...
TRANSCRIPT
Focus on Assessment 02
PART 01 ENTITY RELATIONSHIP DIAGRAMS
What is an EnAty RelaAonship Diagram?
• The ERD focuses on Data.
• The name tells us what it is:
– a Diagram – showing the RelaAonship – of all the data EnAAes
How does the ERD Help Us?
• When undertaking process automaAon, very early on, we realize that we need to work carefully with DATA (ulAmately, a database).
• From the point of view of data, a process represents a group of STATES that the data can be in.
• The changing of data from one state to the next is oVen called a TRANSACTION.
How does the ERD Help Us?
Goal
• Capture as much of the meaning of the data as possible
• Organize the data to opAmize its value
Result
• A beXer design that is scalable and easier to maintain
What are the elements of an ERD?
• There are three elements or components of an ERD, and two of them are right in the name:
EnAAes (data object)
RelaAonships (between enAAes)
AXributes (describe enAAes)
EnAty
RelaAonship
AXribute
Elements of an ERD • The last component is STRUCTURE, shown by lines
AXribute
EnAty
RelaAonship
RelaAonship
EnAty
AXribute AXribute
EnAty
AXribute AXribute
Elements of an ERD • The last component is STRUCTURE, shown by lines
AXribute
EnAty
RelaAonship
RelaAonship
EnAty
AXribute AXribute
EnAty
AXribute AXribute
AXribute
EnAty
RelaAonship
RelaAonship
EnAty
AXribute AXribute
EnAty
AXribute AXribute
Elements of an ERD
En-ty • An enAty is an object or concept about which you want to store informaAon.
• For example, Customers and their Contacts.
EnAty
RelaAonship
EnAty
RelaAonship EnAty
AXribute AXribute
AXribute AXribute
AXribute
Elements of an ERD
A0ribute • A characterisAc of the enAty. • For example, Address and PhoneNumber could be aXributes of a Contacts enAty.
RelaAonship
EnAty
RelaAonship
AXribute AXribute
AXribute AXribute
AXribute
EnAty EnAty
Elements of an ERD
Rela-onships • RelaAonships illustrate how two enAAes share informaAon in the structure.
• Always labeled with verbs (verbs show acAon)
RelaAonship
EnAty
RelaAonship EnAty EnAty
AXribute AXribute
AXribute AXribute
AXribute
Elements of an ERD Rela-onships Guidelines for defining relaAonships
• Avoid vague names
• DefiniAon explains what acAon is being taken and why it is important
Include ExplanaAons as Needed
• Give examples to clarify the acAon
• OpAonal parAcipaAon should be explained • Explain reasons for any explicit maximum or minimum instances
• Explain any restricAons on parAcipaAon in the relaAonship • Explain extent of the history that is kept in the relaAonship
ERD – Beyond the Essay Assignment
Advanced ERD Concepts
• To be complete, we will now discuss some of the more advanced aspects of ERDs
• These aspects are not required for your essay, though they may be needed for your final exam.
ERD – Beyond the Essay Assignment A0ributes -‐ Primary Keys • Are always a unique aXribute for the enAty (e.g. License
Plate Number – no 2 cars have the same) • Every instance of that enAty must have 1 and only 1 • Are used in relaAonships (e.g. Parking ViolaAons are
connected to your vehicle through the License Plate Number)
A0ributes -‐ Foreign Keys • AXribute used in one enAty to match the primary key
aXribute of another to form the formal relaAonship • This is redundant informaAon (same data in two enAAes) • This redundancy is intenAonal, and necessary • In our example, every Parking ViolaAon enAty must contain
one (and only one) unique License Plate Number
ERD – Beyond the Essay Assignment VEHCILE (a0ributes) (example data)
License Plate Number (Primary Key) GW573Y
Make Renault
Model Kangoo
Year 2009
Insurance Policy Number AIS-‐34579-‐1102-‐91a
PARKING VIOLATION (a0ributes) (example data)
Viola-on Iden-fica-on Number 31959901216231
License Plate Number (Foreign Key) GW573Y
LocaAon 31 Robins Road
Time of Offense 18-‐May-‐2011, 09:08
Class of Offense 2C
DescripAon of Offense Parking on double-‐yellow line
ERD – Beyond the Essay Assignment
Key a0ribute • A key aXribute is the unique, disAnguishing characterisAc of the enAty. For example, an employee's social security number might be the employee's key aXribute.
RelaAonship
EnAty
RelaAonship
AXribute AXribute
AXribute AXribute
AXribute
EnAty EnAty
ERD – Beyond the Essay Assignment
Candidate keys and iden-fiers – Each enAty type must have an aXribute or set of aXributes that disAnguishes one instance from other instances of the same type
Candidate key – AXribute (or combinaAon of aXributes) that uniquely idenAfies each instance of an enAty type
ERD – Beyond the Essay Assignment
Mul-valued a0ribute • A mulAvalued aXribute can have more than one value. For example, an employee enAty can have mulAple skill values.
RelaAonship
EnAty
RelaAonship
AXribute AXribute
AXribute AXribute
AXribute
EnAty EnAty
ERD – Beyond the Essay Assignment
Derived a0ribute • A derived aXribute is based on another aXribute. For example, an employee's monthly salary is based on the employee's annual salary.
RelaAonship
EnAty
RelaAonship
AXribute AXribute
AXribute AXribute
AXribute
EnAty EnAty
ERD – Beyond the Essay Assignment
Iden-fier
• A candidate key that has been selected as the unique idenAfying characterisAc for an enAty type
Selec-on rules for an iden-fier
1. Choose a candidate key that will not change its value 2. Choose a candidate key that will never be null (empty)
3. Avoid using intelligent keys 4. Consider subsAtuAng single value surrogate keys for
large composite keys
ERD – Beyond the Essay Assignment
Weak En-ty • A weak enAty is an enAty that must defined by a foreign key relaAonship with another enAty as it cannot be uniquely idenAfied by its own aXributes alone.
ORDER ORDER ITEMS
has
Primary (unique) Key
Foreign (non-‐unique) Key MyOrderNo
ItemNo OrderNo
ERD – Beyond the Essay Assignment
Minimum Cardinality • The minimum number of instances
of enAty B that may be associated with each instance of enAty A
• This is also called “modality”. Maximum Cardinality • The maximum number of instances
of enAty B that may be associated with each instance of enAty A
Rela-onship Cardinality • The number of instances of enAty B that can be associated
with each instance of enAty A.