400 likes | 613 Views
Data Modeling Using the Entity-Relationship Model. เนื้อหา. การออกแบบฐานข้อมูล Entity-Relationship Model หลักการของอีอาร์โมเดล กรณีตัวอย่าง การทำแผนภาพอีอาร์. Entity Relationship Data Model. ER-Model describes data as Entities Attributes Relationships. Entities และ Attributes.
E N D
เนื้อหา • การออกแบบฐานข้อมูล • Entity-Relationship Model • หลักการของอีอาร์โมเดล • กรณีตัวอย่าง • การทำแผนภาพอีอาร์
Entity Relationship Data Model ER-Model describes data as • Entities • Attributes • Relationships
Entities และ Attributes • Entityคือ วัตถุสิ่งของหรือนามธรรมที่เราสนใจ • Entityอาจเป็นออปเจกที่จับต้องได้ (object with a physical existence) เช่น person, car , house, employee • Entityอาจเป็นออปเจกเชิงหลักการ (object with a conceptual existence)เช่น job, a university course.
Attributes • Attributeคือ คุณสมบัติเฉพาะที่ใช้อธิบายเอนติตี หรือ เป็นคุณสมบัติของเอนติตีแต่ละตัวนั่นเอง • ค่าของแอตตริบิว (attribute values)ที่อธิบายแต่ละเอนติตีคือข้อมูลทีถูกเก็บในฐานข้อมูลต่อไป • ตัวอย่าง • เอนติตี Employee มีคุณสมบัติดังต่อไปนี้ • ชื่อพนักงาน (Name), อายุ (Age), ที่อยู่ (address), เงินเดือน (salary)และตำแหน่งงาน(job)
Attribute & Attribute Value Attribute Student Name Faculty Major ID 475020126-3 Kamonphon Science IT 465020100-0 PiyathiDa Science Comp SC. Attribute Value
Attribute Type • Atomic Attribute • Composite Attributes • Single-Valued • Multi Valued • Stored Attribute • Derived Attribute
Atomic Simple Atomic Attribute • Atomic Attribute คือแอตตริบิวที่ไม่สามารถแยกย่อยออกไปได้อีก • เรียกว่าAtomicหรือSimple Attributes. • ตัวอย่างเช่น Student First Name Last Name Age
Composite Attribute Street Address ZipCode Tambol Province District Composite Attribute? Atomic Attribute Composite Attributes • Composite Attributes สามารถที่จะแบ่งออกเป็นส่วนของแอตตริบิวย่อย ที่มีความหมายที่เป็นอิสระต่อกันได้ Address
Single-Valued VS Multi Valued Attributes • Single-Valued : แอตตริบิวที่มีค่าเพียงค่าเดียวสำหรับเอนติตีใดๆ • Multi Value Attribute: มีค่าได้หลายค่า
Attribute Age Degree A : 24 Years B : 27 Years A : B.Sc. B : B.Sc, M.Sc., Dr. Eng. AttributeValue Example
Stored VS Derived Attributed • Stored Attribute • Derived Attribute: คือค่าของแอตตริบิวดังกล่าวสามารถกำหนดหรือคำนวณจากแอตตริบิวอื่นๆ หรือ เอนติตีอื่นๆ ที่มีความเกี่ยวข้องกันได้
Attribute Stored Attribute Age Birth Day A : 24 Years B : 40 Years A : 13 July 1980 B : 23 Dec 1964 Derived Attribute AttributeValue Example
Key Attribute • KeyAttributeคือแอตตริบิว (หรือกลุ่มของแอตตริบิว) ที่ค่าของมันสามารถใช้แยกความแตกต่างของเอนติตีแต่ละตัวในเอนติตีเซตได้ หรือกล่าวได้ว่าเป็นแอตตริบิวที่ใช้เป็นตัวแทนของแต่ละเอนติตีในเอนติตีเช็ค • คุณสมบัติของคีย์แอตตริบิว • Unique • Not Null
Null Value สำหรับบางกรณีเอนติตีบางตัวอาจไม่มีค่าปรากฏในบางแอตตริบิว ยกตัวอย่างเช่น Degree attributeจะปรากฏค่าเฉพาะสำหรับคนที่สำเร็จการศึกษาในระดับวิทยาลัย/มหาวิทยาลัย ในสถานการณ์ดังกล่าวค่าของ Degree attribute จะมีค่าพิเศษเรียกว่าค่า null
Entity Type • Strong Entity Type • คือเอนติตีที่มีคีย์แอตตริบิวของตนเอง (Entity that do have a key attribute) • Weak Entity Type • คือเอนติตีที่ไม่มีคีย์แอตตริบิวของตนเอง • เป็นเอนติตีที่ขึ้นกับเอนติตีอื่น(Depend on other entities) • เอนติตีที่ถูกขึ้นตรงจะเรียกว่า owner entity • ความสัมพันธ์ระหว่าง Owner กับ Weak entities ถูกเรียกว่า “identifying relationship”
Example • Entity • Employee • Department • Project • Dependent
Entity Type, Entity Sets, Keys, Value Set • Entity typeคอลเลกชันหรือเซตของเอนติตีที่มีแอตตริบิวเหมือนกัน • แต่ละ entity type ในฐานข้อมูลจะต้องมีการกำหนดชื่อของเอนติตีและแอตตริบิวเป็นตัวแสดงคุณสมบัติ • Entity set คือคอลเลกชันของเอนติตีในขณะใดขณะหนึ่ง • Entity set ปกติใช้ชื่อเดียวกันกับเอนติ entity type.
Relationshipเป็นความสัมพันธ์ระหว่างเอนติตีRelationshipเป็นความสัมพันธ์ระหว่างเอนติตี
Relationship Type • Relationship type Rระหว่าง n entity types E1,E2,…,En • บอกกลุ่มความสัมพันธ์(association or relationship) ระหว่าง entities • Mathematically, • the relationship set R • คือเซตของความสัมพันธ์ ri, • โดยที่แต่ละ riสัมพันธ์กับ n individual entities (e1,e2,…, en) • และแต่ละเอนติตี ejใน riคือสมาชิกของแต่ละเอนติตีEj, 1 ≤ j ≤ n.
Relationship Degree • Degreeของ relationship type คือจำนวนของเอนติตีเช็ค ที่เกิดความสัมพันธ์กัน • For example - Degreeของความสัมพันธ์ระหว่างอาจารย์และนักศึกษาจะมี ค่าเท่ากับ สอง - Degreeที่มีค่าเท่ากับสองเรียกว่า binary สาม คือ ternary ตามลำดับ
Constraint on Relationship Types • Two main Type of relationship constraints • Cardinality ratio • Participation
Cardinality Ratios • Cardinality ratioกำหนดค่ามากสุดของสมาชิกของความสัมพันธ์ที่เอนติตีเข้าไปมีส่วนเกี่ยวข้อง • 1 to 1 Relationship (1:1) • 1 to many relationship (1:N) • Many to Many relationship (N:M)
1:1 Relationship R1 R2 R3 R4 T1 T2 T3 T4 T5 T6 T7 D1 D2 D3 D4 Entity E2 Entity T Relationship
1:1 Relationship Head Head Head Head Apisak Pusadee Pramot Somjit Pattana Kriat Sartra CompSc Stat Physics Math Entity E2 Entity T Relationship
1 to Many Relationship R1 R2 R3 R4 E1 E2 E3 E4 E5 E6 E7 D1 D2 D3 D4 Entity D Entity E Relationship
1:1 Relationship work Work Work Work Apisak Pusadee Somjit Pramot Pattana Tasanee Jirasuk CompSc Stat Physics Math Entity E2 Entity T Relationship
E1 E2 E3 E4 E5 E6 E7 J1 J2 J3 J4 Entity J Entity E Many to Many Relationship R1 R2 R3 R4 Relationship
Aim Daw Dam Aun Nuu Nam F Project File&DB English Cal Subject Student Many to Many Relationship R1 R2 R3 R4 Register
Participation Constraints and Existence Dependencies • Participation Constraints • เป็นการระบุว่าสมาชิกเอนติตีในเอนติตีเซ็ตขึ้นกับเอนติตีอื่นโดยผ่านทางความสัมพันธ์ • มันจะระบุจำนวนที่น้อยที่สุดของสมาชิกในเอนติตีที่มีความสัมพันธ์หรือที่เกี่ยวข้องไว้ ซึ่งเราเรียกว่าminimum cardinality constraint.
Participation type • Partial participation • Total participation (existence dependency)
Total participation R1 R2 R3 R4 E1 E2 E3 E4 E5 E6 E7 D1 D2 D3 D4 Entity แผนก Relationship สังกัด Entity พนักงาน
E1 E2 E3 E4 E5 E6 E7 D1 D2 D3 D4 Partial participation R1 R2 R3 R4 Entity E Entity D Relationship
Entity Weak Entity Relationship Symbol
Weak Entity Attribute Key Attribute Composite Attribute Derived Attribute
E1 E2 R E1 E2 R 1 N partial Total Cardinality Ratio