Lecture2 Erd
Lecture2 Erd
1
Overview
SDLC phases
Planning Analysis Design Implementation Maintenance
2
Entity-Relationship (ER) Diagram
Business Rules
Each department must have many staff.
Each staff may belong to one department.
ER Diagram
DEPARTMENT has STAFF
D_ID S_ID
D_Name S_Name
3
Business Rules
• Define or constrain some aspect of the business
• Names and definitions of entity types, attributes and relationships
• Constraints on above data objects
4
Represent business rules by ERD
Business rules
5
ERD Components – Entities and Attributes
ENTITY NAME
Identifier
Attributes Partial identifier
Simple attribute
[Derived]
{Multivalued}
Composite (1, 2, 3)
6
ERD Components - Relationships
Binary Ternary
Unary
Relationship
Binary
Relationship
Cardinality
Mandatory one Mandatory many Optional one Optional many
Associative
Entity Type Associative
7
What Should An Entity Be?
8
What Should An Entity Be?
9
What Should An Entity Be?
10
What Should An Entity Be?
Student Information System
11
What Should An Entity Be?
TRANSCRIPT
Student_Name
Transcript is NOT entity.
Course_Name
Relevant to the business Semester It is just an output
Grade generated from other
entities !!
Multiple Instances –
Should not be a single user! Student Information System
12
Practice: A database analyst identified some entities of
an accounting system, which entities are invalid?
manages summarizes
is charged
ACCOUNT EXPENSE
13
Report
A single person generated from
“EXPENSE”
manages summarizes
is charged
ACCOUNT EXPENSE
14
ERD EXAMPLE OF A BUSINESS
15
ERD of a Startup Travel Agency – 1st Year
Entity Type: DEPARTMENT STAFF
D_ID has S_ID
D_Name S_Name
001 Peter Li
Entity Instance: A Development 002 Mary Chan
003 Anna Lee
B Marketing 004 Tom Lee
005 John Lam
16
ERD of the Travel Agency – 2nd Year
STAFF
DEPARMENT
S_ID
D_ID has S_Name
D_Name
is entitled to
Entity Instance:
BENEFIT 001 MTR
B_CODE
002 MTR & Taxi
B_DESC
003 MTR & Taxi & Air
17
ERD of the Travel Agency – 3rd Year
001 Peter Li
DEPARMENT STAFF 003 Anna Lee
D_ID S_ID
has
D_Name S_Name
has
is entitled to
18
ERD of the Travel Agency – 3rd Year
001 Peter Li
DEPARMENT STAFF 003 Anna Lee
D_ID S_ID
has
D_Name S_Name
identifying
relationship
has
is entitled to
19
ERD of the Travel Agency – 3rd Year
001 Peter Li
DEPARMENT STAFF 003 Anna Lee
D_ID S_ID
has
D_Name S_Name
identifying
relationship
has
is entitled to
20
ERD of the Travel Agency – 3rd Year
001 Peter Li
DEPARMENT STAFF 003 Anna Lee
D_ID S_ID
has
D_Name S_Name
identifying
relationship
has
is entitled to
21
ERD of the Travel Agency – 3rd Year
001 Peter Li
DEPARMENT STAFF 003 Anna Lee
D_ID S_ID
has
D_Name S_Name
identifying
relationship
has
is entitled to
22
Strong vs. Weak Entity Type
DEPARMENT BENEFIT STAFF FAMILY
has
D_ID B_CODE S_ID Name
D_Name B_DESC S_Name Birthdate
23
Strong vs. Weak Entity Type
DEPARMENT BENEFIT STAFF FAMILY
has
D_ID B_CODE S_ID Name
D_Name B_DESC S_Name Birthdate
24
Strong vs. Weak Entity Type
DEPARMENT BENEFIT STAFF FAMILY
has
D_ID B_CODE S_ID Name
D_Name B_DESC S_Name Birthdate
25
DIFFERENT TYPES OF ATTRIBUTES
26
Attributes
• Property or characteristic of an entity type
• Classifications of attributes
• Simple attributes ENTITY NAME
• Composite attributes
Identifier
Simple attribute
• Multivalued attributes
Composite (1, 2, 3)
{Multivalued}
• Derived attributes
[Derived]
• Identifier attributes
27
Example of Employee entity
EMPLOYEE
Employee_ID
Date Employed
Employee_Name
(First Name, Last Name)
Employee Address
(Street Address, City,
State, Postal Code)
{Skills}
[Years Employed]
28
Example of Employee entity
EMPLOYEE
Employee_ID
Identifier attribute
Date Employed
Employee Address
(Street Address, City,
State, Postal Code)
{Skills}
[Years Employed]
29
Example of Employee entity
EMPLOYEE
Employee_ID
Date Employed
Composite attribute
Employee_Name
(First Name, Last Name)
Employee Address
(Street Address, City,
Component attributes
State, Postal Code)
{Skills}
[Years Employed]
30
Example of Employee entity
EMPLOYEE
Employee_ID
Date Employed
Employee_Name
(First Name, Last Name)
Composite attribute
Employee Address
(Street Address, City,
State, Postal Code)
[Years Employed]
31
Example of Employee entity
EMPLOYEE
Employee_ID
Date Employed
Employee_Name
(First Name, Last Name)
Employee Address
(Street Address, City,
State, Postal Code)
Multivalued attribute
{Skills}
[Years Employed]
32
Example of Employee entity
EMPLOYEE
Employee_ID
Date Employed
Employee_Name
(First Name, Last Name)
Employee Address
(Street Address, City, Years Employed = (Current Date - Date Employed)/365.25
State, Postal Code)
{Skills}
Derived attribute
[Years Employed]
33
Identifier Attribute/Key
34
1. Simple identifier
35
1. Simple identifier
2. Composite identifier
36
Characteristics of Identifiers
• Will not be null
• Can one’s student ID be “[null]”?
• Will not change in value
• In HKUST : UG student ID = PG student ID = Staff ID
• No intelligent identifiers
• Should we use “LSK4066Samuel” as an identifier?
37
CARDINALITY CONSTRAINTS
38
ERD of a Startup Travel Agency – 1st Year
Relationship DEPARTMENT STAFF
Type: D_ID has S_ID
D_Name S_Name
001 Peter Li
Relationship A Development
002 Mary Chan
Instance:
003 Anna Lee
B Marketing 004 Tom Lee
005 John Lam
39
ERD of a Startup Travel Agency – 1st Year
Relationship DEPARTMENT STAFF
Type: D_ID has S_ID
D_Name S_Name
001 Peter Li
Relationship A Development
002 Mary Chan
Instance:
003 Anna Lee
B Marketing 004 Tom Lee
005 John Lam
40
Cardinality Constraints
DEPARTMENT STAFF
D_ID has S_ID
D_Name S_Name
001 Peter Li
A Development
002 Mary Chan
003 Anna Lee
B Marketing 004 Tom Lee
005 John Lam
42
Cardinality Constraints
DEPARTMENT STAFF
D_ID has S_ID
D_Name S_Name
No associated
001 Peter Li
department
A Development
002 Mary Chan
003 Anna Lee
B Marketing 004 Tom Lee
005 John Lam
43
Cardinality Constraints Summary
Minimum Cardinality
Optional Mandatory
One
Optional one Mandatory one
Range: 0 or 1 Range: 1
Maximum
Cardinality
Many
Optional many Mandatory many
Range: 0, 1, 2…N Range: 1, 2...N
One-to-one One-to-many
registers for
STUDENT COURSE
Many-to-many
45
Example 1:
Interpret the relationship with cardinality constraints
has PATIENT
PATIENT
HISTORY
46
Example 2:
Interpret the relationship with cardinality constraints
is assigned
EMPLOYEE LAPTOP
47
ASSOCIATIVE ENTITIES
48
Mandatory many to optional many relationship
between EMPLOYEE and PROJECT
Peter TQM
Debbie OO
Assign_Date
Tom CR
Heidi
is assigned to
EMPLOYEE PROJECT
Assign_Date
Relationship Attribute
50
Converting many to many relationship into associative entity
is assigned to
EMPLOYEE PROJECT
Assign_Date
ASSIGNMENT
Associative Entity
51
Associative Entities
ASSIGNMENT
EMPLOYEE Assign_Date PROJECT
⚫ An instance of the associative entity belongs to exactly one employee and one project
53
DEGREE OF A RELATIONSHIP
54
Degree of a Relationship
• Degree of a Relationship is the number of entity types that participate in it
Unary (Degree 1) Binary (Degree 2) Ternary (Degree 3)
One entity related to Two different entity types Three different entity types
another same entity type related to each other related to each other
55
Example 1: Unary Relationship – Optional one to optional one
Shirley
is married to
Eric
David
PERSON
Cathy
Mark
Mary
56
Example 2: Unary Relationship – Optional one to optional many
manages
EMPLOYEE
57
Example 3: Unary Relationship – Optional many to optional many
is composed of
A
B
ITEM
C
58
An example: Car parts
is composed of
Sporty Rim Rim Body Japan Wheel Cap
(Type A1)
ITEM
59
An example: Car parts Item_ID: 801
“Sporty Rim” is Sporty Rim
composed Component items:
of 2 items Rim body (Type A1),
Japan Wheel cap
is composed of
“Race Wheel” is Item_ID: 1002
composed of a Race Wheel
“Sporty Rim” and Component items:
ITEM 2 other items Sporty Rim,
Fast Tire, Air valve
Item_ID: 6601
“Fast Tire” is not Fast Tire
composed by Component items:
extra items None
60
An example: Car parts Item_ID: 801
Sporty Rim
Component items:
Rim body (Type A1),
Japan Wheel cap
is composed of
Item_ID: 1002
Race Wheel
Component items:
ITEM The same item -
Sporty Rim,
Fast Tire, Air valve
“Sporty Rim” is
included
in 2 other items Item_ID: 1003
Snow Racing Wheel
Component items:
Sporty Rim,
Snow Tire, Air valve
61
Example 4: Ternary Relationship – an example of a factory
PART
supplies
VENDOR WAREHOUSE
Shipping Mode
Unit Cost
62
PART
SUPPLY SCHEDULE
Shipping Mode
VENDOR Unit Cost WAREHOUSE
63
DBMS, BUSIENSS RULES AND ERD
• Business rules are automated through DBMS software
• Some business rules cannot be represented in E-R diagram and
implemented in DBMS; instead they are stated in natural language
64