Download - บทที่ 4 er diagram
หนวยการเรยนท 4
ER-Diagram
2ระบบฐานขอมล
Entity Sets เราสามารถท าแบบจ าลองของ Database ใหอยในลกษณะดงน
เปนกลมของ entities
relationship ระหวาง entities.
Entity คอ สงทคงอย สามารถระบไดในความจรง และสามารถแยกแยะออกไดจากสงอนๆ.ตวอยางเชน: บคคลใดบคคลหนง , บรษท , เหตการณ, สถานท
Entities แตละตวสามารถม property ไดหลาย propertyตวอยางเชน: บคคล ม ชอ , ทอย , อาย, เพศ ฯลฯ
Entity set คอกลมของ entities ทมคณสมบตทเหมอนกน ซงใช propertiesรวมกน ตวอยางเชน : กลมของบคคลหลายๆ คน, บรษทหลายๆ บรษท, เหตการณหลายๆ เหตการณ, สถานทหลายๆ สถานท
3ระบบฐานขอมล
Entity Sets (ตอ)Entity ใน E-R Model แบงออกเปน 2 ประเภทคอ
1. Regular Entity ไดแก Entity ซงสมาชกภายใน Entity มคณสมบตIdentity ไดดวยตวของมนเอง ( Identity คอ Entity ทม Property ทสามารถก าหนดเปนเอกลกษณเฉพาะใหกบแตละ Entity ได)
EmpID NAME SEX SALARY
00001 สมชาย นลกลด M 8,500
00002 เจรญ กาวหนา M 9,000
00003 ชตมา สกลด F 10,000
Entity “EMPLOYEE”
EMPLOYEE
4ระบบฐานขอมล
Entity Sets (ตอ)2. Weak Entity ไดแก Entity ซงสมาชกภายใน Entity จะมคณสมบต
Identity ได ตองอาศย Property ของ Regular Entity มาประกอบกบ Property ของตวมนเอง
EmpID Date Time_In Time_Out
00001 15/9/46 7.30 17.30
00002 15/9/46 7.30 17.30
00003 15/9/46 7.45 17.45
00001 16/9/46 8.00 19.00
00002 16/9/46 8.25 17.30
00003 16/9/46 8.00 19.00
Entity “TIME_IN_OUT”
TIME_IN_OUT
5ระบบฐานขอมล
Property (Attributes)
Property คอคณลกษณะตางๆ ของ Entity ตวอยางเชนEMPLOYEE = (EmpId, NAME,SEX,SALARY)
EmpID NAME SEX SALARY
00001 สมชาย นลกลด M 8,500
00002 เจรญ กาวหนา M 9,000
00003 ชตมา สกลด F 10,000
Property
Entity
6ระบบฐานขอมล
ประเภทของ Property :
1. Simple Property ไดแก Property ทคาภายใน Property นนไมมการแบงยอยอก
7ระบบฐานขอมล
ประเภทของ Property (ตอ)
2. Composite Property คอ Property ทคาภายใน Property นน มการแบงแยกเปน Property ยอยอก
EMPLOYEEEmpID
NAME SEX SALARY
FNAME
SNAME
8ระบบฐานขอมล
ประเภทของ Property (ตอ)
3. Key คอ Property หรอกลมของ Property ทมคาในแตละสมาชกของ Entity ไมซ ากน
EMPLOYEEEmpID
NAME SEX SALARY
FNAME
SNAME
9ระบบฐานขอมล
ประเภทของ Property (ตอ)
4. Single-valued Property เปน Property ทมคาขอมลภายในProperty เพยงคาเดยว เชน EmpID, NAME, SEX, SALARY
5. Multi-valued Property เปน Property ทมคาขอมลภายในProperty ไดหลายคา
10ระบบฐานขอมล
Resolving Multivalued Attribute Problems
ใน conceptual model สามารถรองรบ multivalued attributes ได แตไมสามารถสรางใน relational DBMS ได มวธแกไข 2 แบบคอ
สรางแอตทรบวสใหมส าหรบแตละ multivalued attribute’s components เดม
ท าใหเกดปญหาทางดานโครงสรางตามมาได
สรางเอนทตใหม ซงประกอบดวย multivalued attribute’s components เดม
11ระบบฐานขอมล
Splitting the Multivalued Attribute into New Attributes
12ระบบฐานขอมล
Components of the Multivalued Attribute
13ระบบฐานขอมล
A New Entity Set Composed of a Multivalued Attribute’s Components
14ระบบฐานขอมล
ประเภทของ Property (ตอ)
6. Derived Property คอ Property ทไดมาจากการน า Property อนมาค านวณ ซงคาจะมการเปลยนแปลงทกครงท Property ทน ามาค านวณเปลยนแปลง
ตวอยางเชน อาย, ไดมาจากการน า วนเกด มาค านวณ
ไมจ าเปนตองเกบขอมลไวในฐานขอมล
15ระบบฐานขอมล
Depiction of a Derived Attribute
16ระบบฐานขอมล
สรปสญลกษณใน E-R Diagram (แบบ Chen)สญลกษณ ความหมาย
Entity
Weak Entity
Relationship
Weak Relationship
Composite Entity หรอ Gerund
Attribute
Multi – Value Attribute
Primary Key Attribute
Composite Attribute
Derived Attribute
17ระบบฐานขอมล
Relationship Sets
Relationship หมายถงความสมพนธระหวาง Entity
EMPLOYEEEmpID
NAME SEX SALARY DEP_NAME
DEPARTMENT
DEP_ID
WORK_IN
18ระบบฐานขอมล
RelationshipRelationship สามารถน า Property ทท าหนาทเปน Key ของ Entity ท
มความสมพนธกน มาสรางเปน Relationship ได และสามารถม Property เปนของตวเองได
STUDENT
SID SNAME
COURSE
CID CNAME
TAKE
GRADE
19ระบบฐานขอมล
Relationship
PERSON CITYWAS_BORN_IN
LIVES_IN
Relationship ระหวาง Entity ใดๆ สามารถมความสมพนธระหวางสมาชกใน Entity เหลานนไดมากกวา 1 ความสมพนธ
20ระบบฐานขอมล
The M:N Relationship Between STUDENT and CLASS
21ระบบฐานขอมล
A Composite Entity in an ERD
22ระบบฐานขอมล
Degree ของ Relationship Set คอจ านวนของ entity sets ทม relationship set รวมกน.
Relationship sets ทเกดขนระหวาง 2 entity sets ใดๆ เรยกวา binary (หรอ มdegree เทากบ 2) ซงพบมากทสดในแผนภาพ E-R
Relationship sets ทเกดขนระหวาง 3 entity เรยกวา ternary หรอเรยก Relationship sets ทเกดขนระหวาง entity ทมากกวา 2 entity วา N-ary Relationship
23ระบบฐานขอมล
Three Types of Relationships
24ระบบฐานขอมล
The Implementation of a Ternary Relationship
25ระบบฐานขอมล
Recursive Relationshipเปน Relationship ทเกดขนกบ Entity เดยว ในกรณท Property ของ Entity
นน สามารถสรางความสมพนธกบอก Property หนงภายใน Entity เดยวกน
EMPLOYEE
EmpID NAME SEX SALARY
MANAGER_OF
26ระบบฐานขอมล
An ER Representation of Recursive Relationships
27ระบบฐานขอมล
The 1:1 Recursive Relationship “EMPLOYEE is Married to EMPLOYEE”
28ระบบฐานขอมล
Implementation of the 1:M “EMPLOYEE Manages EMPLOYEE” Recursive Relationship
29ระบบฐานขอมล
Implementation of the M:N Recursive “PART Contains PART” Relationship
30ระบบฐานขอมล
Various Implementations of a 1:1 Recursive Relationship
31ระบบฐานขอมล
Composite Entities
Also known as bridge entities
Composed of the primary keys of each of the entities to be connected
May also contain additional attributes that play no role in the connective process
32ระบบฐานขอมล
The M:N Relationship Between STUDENT and CLASS
33ระบบฐานขอมล
A Composite Entity in an ERD
34ระบบฐานขอมล
Converting the M:N Relationship into Two 1:M Relationships
35ระบบฐานขอมล
RELATIONSHIP Strength Existence dependence
Entity’s existence depends on the existence of one or more other entities
Existence independence
Entity can exist apart from one or more related entities
Weak (non-identifying) relationships
One entity is not existence-independent on another entity
Strong (Identifying) Relationships
Related entities are existence-dependent
36ระบบฐานขอมล
Existence Dependency
If an entity’s existence depends on the existence of one or more other entities, it is said to be existence-dependent.
37ระบบฐานขอมล
A Weak (Non-Identifying) Relationship Between COURSE and CLASS
38ระบบฐานขอมล
A Weak Relationship Between COURSE and CLASS
39ระบบฐานขอมล
A Strong (Identifying) Relationship Between COURSE and CLASS
40ระบบฐานขอมล
Relationship Strength and Weak Entities
Weak entity meets two conditions
Existence-dependent:
Cannot exist without entity with which it has a relationship
Has primary key that is partially or totally derived from the parent entity in the relationship
41ระบบฐานขอมล
A Weak Entity in an ERD
42ระบบฐานขอมล
A Weak Entity in a Strong Relationship
43ระบบฐานขอมล
Connectivity ใชอธบายประเภทของความสมพนธของเอนทต
( one-to-one, one-to-many, and many-to-many).
Connectivity
44ระบบฐานขอมล
Connectivity
Dean Faculty
One-to-One Relationship
Faculty TeacherWork_IN1 M
One-to-Many Relationship
Dean FacultyDean_of
1 1
Faculty Teacher
Chen
Crow’s Foot
Chen
Crow’s Foot
45ระบบฐานขอมล
Connectivity
Student CourseEnrollM M
Many-to-Many Relationship
Student Couse
Chen
Crow’s Foot
46ระบบฐานขอมล
Cardinalities
คอการระบจ านวน ทสมาชกใน Entity หนงสามารถมความสมพนธกบสมาชกในอกเอนทตหนงได
47ระบบฐานขอมล
Connectivity and Cardinality in an ERD
48ระบบฐานขอมล
หมายถง ลกษณะของความสมพนธทเกดขนระหวางเอนทต
แบบเลอกได (optional)
แบบบงคบ (mandatory)
ใชเครองหมายวงกลมเลก เพอแทนความสมพนธแบบ เลอกได
การมสวนรวมในความสมพนธ (Relationship Participation)
49ระบบฐานขอมล
CLASS is Optional to COURSE
COURSE and CLASS in a Mandatory Relationship
Relationship Participation
50ระบบฐานขอมล
Cardinalities และ Participation แบบ Chen
51ระบบฐานขอมล
Cardinalities และ Participation แบบ Crow’s Foot
Mandatory One
Mandatory Many
Optional One
Optional Many
52ระบบฐานขอมล
Total participation (แสดงแทนดวยเสนค): ทกๆ entity ใน entity set participates อยางนอยเทากบ 1 relationship ใน relationship set (บางครงเรยก Mandatory)
Partial participation: บาง entities อาจจะไม participate กบ relationship ใน relationship set เลยกได (บางครงเรยก Optional)
ตวอยาง การมสวนรวมในความสมพนธ แบบอน
53ระบบฐานขอมล
The generalization hierarchy depicts the parent-child relationship.
The supertype contains the shared attributes, while the subtype contains the unique attributes.
A subtype entity inherits its attributes and its relationships from the supertype entity.
Entity Supertypes and Subtypes
54ระบบฐานขอมล
A Generalization Hierarchy
55ระบบฐานขอมล
The supertype entity set is usually related to several unique and disjointed (nonoverlapping) subtype entity sets.
The supertype and its subtype(s) maintain a 1:1 relationship.
Entity Supertypes and Subtypes
56ระบบฐานขอมล
A Generalization Hierarchy With Overlapping Subtypes
Overlapping
NonOverlapping
57ระบบฐานขอมล
Generalization และ Specialization แบบอน
เปนการแบงสมาชกของ Entity Set ออกเปน Entity Set ยอย ในลกษณะ Top-down design process;
Entity Set ยอย (Subset Entity) ใน lower-level จะม Property และ participate ทเหมอนกบ Entity ใน higher-level (Superset Entity)นอกจากน Entity Set ยอย ยงสามารถม Property เพมเตมทใชบงบอกความแตกตางของสมาชกใน Entity ยอยเหลานน
จะใช รป สามเหลยม ทมลาเบลวา “ISA” (E.g. customer “is a” person) เปนสญลกษณ.
58ระบบฐานขอมล
Specialization Example
59ระบบฐานขอมล
Generalization
เปนการรวมจ านวนของ Entity Set ทมคณสมบตทเหมอนกนขนไปยง higher-level entity set.
Specialization และ generalization จะมลกษณะตรงขามกน แตใชในการอธบายความหมายเดยวกนใน E-R diagram.
EMPLOYEE
EmpID NAME SEX SALARY
MALE FEMALE
MILITARY_STATUS
60ระบบฐานขอมล
Coverage Property
คอ ความสมพนธระหวางจ านวนสมาชกของ Superset Entity ทมความสมพนธไปยง Subset Entity สามารถแบงไดเปน 4 แบบคอ
Total Coverage คอ การทสมาชกใน Superset Entity มความสมพนธกบสมาชกใน Subset Entity อยางนอย 1 Entity ใชตวอกษรตว “t” แทนสญลกษณ
Partial Coverage คอ มบางสมาชกใน Superset Entity ไมมความสมพนธกบสมาชกใน Subset Entity ใดเลย ใชตวอกษร “p” แทนสญลกษณ
Exclusive Coverage คอ สมาชกใน Superset Entity มความสมพนธกบสมาชกใน Subset Entity ใด Entity หนงเทานน ใชตวอกษร “e” แทนสญลกษณ (หรอเรยก Disjoint)
61ระบบฐานขอมล
Coverage Property (ตอ)Overlapping Coverage คอ สมาชกใน Superset Entity มความสมพนธกบ
สมาชกใน Subset Entity ไดมากกวา 1 Entity ใชตวอกษร “o” แทนสญลกษณ
PERSON
MALE FEMALE EMPLOYEESECRETARYMANAGER
ADVERTISING_EMPLOYEE
SALE_EMPLOYEE
PROGRAMMER
(t,e) (p,e)
(p,o)
62ระบบฐานขอมล
Coverage Property (ตอ)ใน E-R Diagram รปแบบอน จะใชค าอธบายดงน
ใช Total และ Partial เพออธบายความสมพนธ ของ Superset Entity กบ Subset Entity วา ตองมหรอไมตองมกได
ใช Disjoint แทนความหมายของ Exclusive Coverage
ใช Overlapping แทนความหมายของ Overlapping Coverage
63ระบบฐานขอมล
A Supertype/Subtype Relationship in an ERD
64ระบบฐานขอมล
สรปสญลกษณใน E-R Diagram (แบบ Chen)สญลกษณ ความหมาย
Entity
Weak Entity
Relationship
Weak Relationship
Composite Entity หรอ Gerund
Attribute
Multi – Value Attribute
Primary Key Attribute
Composite Attribute
Derived Attribute
65ระบบฐานขอมล
66ระบบฐานขอมล
The Completed Tiny College ERD