Entity-Relationship Modelنموذج الكيان والعلاقة

الشريحة 1 من 28

مقدمة الفصل

ماذا ستتعلم في هذا الفصل

  1. The design phases and the steps of building a database; data models and the ER model.
  2. Entity sets, relationship sets, degree, mapping cardinalities and the kinds of attributes.
  3. Existence dependence, weak entities, and how ER diagrams draw entities, relationships, roles and constraints.
  4. Cardinality and participation in Chen and crow's foot notation.
  5. Reduction to relation schemas; specialization, generalization, completeness and disjointness; aggregation; design issues and UML.
تفاصيل المصدرالفصل 5.1 · الشريحة ⁦2⁩
المصدر
الفصل 5.1 · الشريحة ⁦2⁩

Design phasesمراحل التصميم

Design phases (slides 3–4)

  1. 1

    Characterize fully the data needs of the prospective database users.

  2. 2

    Choose a data model and translate the requirements into a conceptual schema (which also indicates the functional requirements — the operations performed on the data).

  3. 3

    Logical design — the database schema: how data is structured logically (entities, attributes, keys, relationships).

  4. 4

    Physical design — the physical layout: how data will be stored (storage, performance).

Logical design involves two decisions (slide 4)

  • Business decision — what attributes should we record in the database?
  • Computer Science decision — what relation schemas should we have and how should the attributes be distributed among the various relation schemas?

Steps in building a database (slide 5)

  1. 1

    Understand the real-world domain

  2. 2

    Specify it with a conceptual model (ER)

  3. 3

    Translate to the DBMS model (relational)

  4. 4

    Create the schema (DDL)

  5. 5

    Load data (DML)

Design approaches (slide 6)

  • Entity Relationship Model (covered in this chapter) — models an enterprise as a collection of entities and relationships, represented diagrammatically by an entity-relationship diagram.
  • Normalization Theory (Chapter 6) — formalize what designs are bad, and test for them.

In the steps of building a database for an application, what comes directly after specifying the domain with a conceptual model (ER)?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦3–6⁩
المصدر
الفصل 5.1 · الشرائح ⁦3–6⁩

Data models and the ER modelنموذج الكيان والعلاقة

The data model (slide 8)

  • A plan or blueprint for a database design.
  • More generalized and abstract than a database design.
  • Easier to change than a database design — the place to work through conceptual problems.
  • Data modeling operates at a high level, starting with conceptual models that capture the essential data and relationships without worrying about technical implementation.

The three basic concepts of the ER model (slide 9)

  • entity sets
  • relationship sets
  • attributes

ER model — database modeling (slide 9)

  • The ER data model was developed to facilitate database design by allowing specification of an enterprise schema that represents the overall logical structure of a database.
  • It is very useful in mapping the meanings and interactions of real-world enterprises onto a conceptual schema; because of this, many database-design tools draw on concepts from the ER model.
  • Its diagrammatic representation, the ER diagram, can express the overall logical structure of a database graphically.
Entityكيان
A "thing" or "object" in the enterprise that is distinguishable from other objects, described by a set of attributes.
Relationshipعلاقة
An association among several entities.

Which are the three basic concepts employed by the ER data model?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦6, 8, 9⁩
المصدر
الفصل 5.1 · الشرائح ⁦6, 8, 9⁩

Entity setsمجموعات الكيانات

Entityكيان

  • An object that exists and is distinguishable from other objects.
  • Example: a specific person, company, event, plant.

Entity setمجموعة كيانات

  • A set of entities of the same type that share the same properties.
  • Example: the set of all persons, companies, trees, holidays.
  • An entity is represented by a set of attributes: instructor = (ID, name, street, city, salary); course = (course_id, title, credits).
  • A subset of the attributes forms a primary key, uniquely identifying each member of the set.

A set of entities of the same type that share the same properties is called:

تفاصيل المصدرالفصل 5.1 · الشريحة ⁦10⁩
المصدر
الفصل 5.1 · الشريحة ⁦10⁩

Relationship sets and degreeمجموعات العلاقات

Entity sets and relationship sets

Relationshipعلاقة
An association among several entities — student 44553 (Peltier) advisor instructor 22222 (Einstein).
Relationship setمجموعة علاقات
A mathematical relation among n ≥ 2 entities, each taken from entity sets: {(e1, …, en) | e1 ∈ E1, …, en ∈ En} — e.g., (44553, 22222) ∈ advisor.
  • An attribute can be associated with a relationship set: advisor may have a date (when the student started with the advisor).
  • Binary relationships involve two entity sets; most relationship sets are binary.
  • proj_guide — students work on research projects under an instructor — is a ternary relationship between instructor, student and project.

Students work on research projects under the guidance of an instructor, recorded by proj_guide. What is the degree of proj_guide?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦12, 14, 15⁩
المصدر
الفصل 5.1 · الشرائح ⁦12, 14, 15⁩

Example: instructor, student and advisorمثال advisor

Entity sets and relationship sets

Entity set instructor (slide 11)
instructor_IDinstructor_name
76766Crick
45565Katz
10101Srinivasan
98345Kim
76543Singh
22222Einstein
Entity set student (slide 11)
student-IDstudent_name
98988Tanaka
12345Shankar
00128Zhang
76543Brown
76653Aoi
23121Chavez
44553Peltier
Relationship set advisor (slide 13) and its attribute date (slide 14): each line of the figure
instructorstudentdate (slide 14)
76766 Crick98988 Tanaka3 May 2008
45565 Katz12345 Shankar10 June 2007
45565 Katz00128 Zhang12 June 2006
10101 Srinivasan76543 Brown6 June 2009
98345 Kim76653 Aoi30 June 2007
76543 Singh23121 Chavez31 May 2007
22222 Einstein44553 Peltier4 May 2006
تفاصيل المصدرالفصل 5.1 · الشرائح ⁦11, 13, 14⁩
المصدر
الفصل 5.1 · الشرائح ⁦11, 13, 14⁩

Mapping cardinalitiesأنماط التعدد

Mapping cardinality constraints

Mapping cardinality constraints
Express the number of entities to which another entity can be associated via a relationship set; for a binary relationship set they are one to one, one to many, many to one, or many to many.
  • Mapping cardinalities are most useful in describing binary relationship sets (slide 16).
  • Note: some elements in A and B may not be mapped to any elements in the other set.
  • In diagrams: directed line (→) = "one"; undirected line (—) = "many" (slide 37).
The four figures of slides 17–18: every line between A and B
FigureالشكلLinesالخطوطNot mappedغير مرتبط
(a) One to one (slide 17)
  • a1–b1
  • a2–b2
  • a3–b3
a4
(b) One to many (slide 17)
  • a1–b1
  • a1–b2
  • a2–b3
  • a2–b4
  • a3–b5
لا تذكر الشرائح شيئًا هنا.
(a) Many to one (slide 18)
  • a1–b1
  • a2–b1
  • a3–b2
  • a4–b3
  • a5–b3
لا تذكر الشرائح شيئًا هنا.
(b) Many to many (slide 18)
  • a1–b1
  • a1–b2
  • a2–b1
  • a3–b3
  • a4–b3
b4

In an E-R diagram, what does a directed line (→) between a relationship set and an entity set signify?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦16, 17, 18, 37⁩
المصدر
الفصل 5.1 · الشرائح ⁦16, 17, 18, 37⁩

Cardinality examples with advisorأمثلة التعدد

Mapping cardinality constraints

advisor between instructor and student (slides 37–40)
CardinalityالتعددAn instructor is associated with…المدرس يرتبط بـA student is associated with…الطالب يرتبط بـ
One-to-manySeveral (including 0) studentsAt most one instructor
Many-to-oneAt most one studentSeveral (including 0) instructors
Many-to-manySeveral (possibly 0) studentsSeveral (possibly 0) instructors
One-to-one (slide 37)لا تذكر الشرائح شيئًا هنا.At most one instructor

advisor is one-to-many from instructor to student. Which statement is correct?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦38–40⁩
المصدر
الفصل 5.1 · الشرائح ⁦38–40⁩

Kinds of attributesأنواع الصفات

Attributes (slides 19–20)
KindالنوعMeaningالمعنىExampleمثال
Composite identifierPrimary key composed of more than one attributeلا تذكر الشرائح شيئًا هنا.
Composite attributeCan be subdivided to yield additional attributesAddress, phone number
Simple attributeCannot be subdividedAge, gender, marital status
Single-valued attributeHas only a single valueA part's serial number (such as SE-08-02-189935)
Multivalued attributeHas many values (should not be implemented in an RDBS)
  • Hobby
  • degree (complex to find the value in a database)
Derived attributeValue calculated from other attributes
  • DOB, employee's age: INT(DATE()-EMP_DOB/365)
  • total cost of order: multiplying the quantity ordered by the unit price

Handling a multivalued attribute (slide 20)

  • 1) Several new attributes, one for each component — can cause structural problems.
  • 2) A new entity composed of the original multivalued attribute's components — the best option.

An order's total cost is calculated by multiplying the quantity ordered by the unit price. What kind of attribute is total cost?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦19–20⁩
المصدر
الفصل 5.1 · الشرائح ⁦19–20⁩

Drawing complex attributesرسم الصفات

Kinds of attributes

Composite attributes (slide 21): composite attributes at the top, component attributes below

composite attributes

name

first_namemiddle_initiallast_name

address

street

street_numberstreet_nameapartment_number
citystatepostal_code
instructor with complex attributes (slide 48)

instructor

ID (primary key, underlined)

name

first_namemiddle_initiallast_name

address

street

street_numberstreet_nameapt_number
citystatezip
{ phone_number }date_of_birthage ( )
  • Composite: components indented under the attribute (name, address, street).
  • Multivalued: in braces — { phone_number }.
  • Derived: followed by parentheses — age ( ).
  • Primary key: underlined — ID.

In an entity rectangle, an attribute is written as { phone_number }. What does this notation mean?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦21, 48, 83⁩
المصدر
الفصل 5.1 · الشرائح ⁦21, 48, 83⁩

Existence dependence and weak entitiesالكيان الضعيف

Existence dependenceمعتمد في وجوده

  • Exists only when associated with another related entity occurrence.
  • A foreign key attribute cannot be null (pk of the other table).

Existence independenceمستقل في وجوده

  • Exists apart from all of its related entities.
  • Called a strong or regular entity.
Weak entity
An entity whose existence depends upon another entity. Conditions: 1. existence-dependent on its parent entity; 2. inherits at least part of its primary key from its parent entity.

من الشرائح

  • EMPLOYEE (EMP_NUM, …) has DEPENDENT; DEPENDENT's key is (EMP_NUM, DEP_NUM) — EMP_NUM comes from EMPLOYEE (slide 24).

DEPENDENT has primary key (EMP_NUM, DEP_NUM), where EMP_NUM comes from EMPLOYEE, and a dependent cannot exist without an employee. What is DEPENDENT?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦22–24⁩
المصدر
الفصل 5.1 · الشرائح ⁦22–24⁩

A weak entity: EMPLOYEE has DEPENDENTمثال الكيان الضعيف

Existence dependence and weak entities

A weak entity in an ERD (slide 24)
EMPLOYEEDEPENDENT
Chen model
  • Single rectangle
  • "1" and (0,N) on its side of has
  • Double rectangle
  • "M", an oval and (1,1) on its side of has
Crow's foot modelTwo bars and (1,1) on its side of hasOval with crow's foot and (0,N) on its side of has
AttributesEMP_NUM (PK), EMP_LNAME, EMP_FNAME, EMP_INITIAL, EMP_DOB, EMP_HIREDATEDEP_NUM (PK), EMP_NUM (PK, FK1), DEP_FNAME, DEP_DOB
A weak entity in a strong relationship — Table name: EMPLOYEE (slide 25, database name: Ch04_ShortCo)
EMP_NUMEMP_LNAMEEMP_FNAMEEMP_INITIALEMP_DOBEMP_HIREDATE
1001CallifanteJeanineJ12-Mar-6425-May-97
1002SmithsonWilliamK23-Nov-7028-May-97
1003WashingtonHermanH15-Aug-6828-May-97
1004ChenLydiaB23-Mar-7415-Oct-98
1005JohnsonMelanieلا تذكر الشرائح شيئًا هنا.28-Sep-6620-Dec-98
1006OrtegaJorgeG12-Jul-7905-Jan-02
1007O'DonnellPeterD10-Jun-7123-Jun-02
1008BrzenskiBarbaraA12-Feb-7001-Nov-03
Table name: DEPENDENT (slide 25)
EMP_NUMDEP_NUMDEP_FNAMEDEP_DOB
10011Annelise05-Dec-97
10012Jorge30-Sep-02
10031Suzanne25-Jan-04
10061Carlos25-May-01
10081Michael19-Feb-95
10082George27-Jun-98
10083Katherine18-Aug-03

Expressing weak entity sets (slide 50)

  • A weak entity set is depicted via a double rectangle.
  • The discriminator of a weak entity set is underlined with a dashed line.
  • The relationship set connecting the weak entity set to the identifying strong entity set is depicted by a double diamond.
  • Primary key for section — (course_id, sec_id, semester, year): section is weak, identified through sec_course by course.
تفاصيل المصدرالفصل 5.1 · الشرائح ⁦24, 25, 50⁩
المصدر
الفصل 5.1 · الشرائح ⁦24, 25, 50⁩

The university design: entity sets and relationship setsتصميم الجامعة

ER diagrams: entities, relationships, roles and naming

Entity sets (slide 27) — **bold** = underlined (the primary key); braces = a multivalued composite attribute
Entity setAttributes
classroombuilding, room_number, capacity
departmentdept_name, building, budget
coursecourse_id, title, credits
instructorID, name, salary
sectioncourse_id, sec_id, semester, year
studentID, name, tot_cred
time_slottime_slot_id, {(day, start_time, end_time)}
Relationship sets: what they relate (slide 27) and how slide 51 draws them
Relationship setمجموعة العلاقةRelates (slide 27)تربطLines in the E-R diagram (slide 51)خطوطها في المخطط
inst_deptinstructors with departments
  • instructor: double line
  • arrow to department
stud_deptstudents with departments
  • student: double line
  • arrow to department
teachesinstructors with sections
  • instructor: single line
  • section: double line
takesstudents with sections, with a descriptive attribute grade
  • student and section: single lines
  • grade attached by a dashed line
course_deptcourses with departments
  • course: double line
  • arrow to department
sec_coursesections with courses
  • double diamond
  • section: double line
  • arrow to course
sec_classsections with classrooms
  • section: double line
  • arrow to classroom
sec_time_slotsections with time slots
  • section: double line
  • time_slot: single line
advisorstudents with instructors
  • student: single line
  • arrow to instructor
prereqcourses with prerequisite coursescourse twice, with the roles course_id and prereq_id
  • On slide 51, section is a double rectangle (a weak entity set) and its sec_id, semester and year are underlined with a dashed line (the discriminator).
تفاصيل المصدرالفصل 5.1 · الشرائح ⁦27, 51⁩
المصدر
الفصل 5.1 · الشرائح ⁦27, 51⁩

The university schema diagramمخطط الجامعة

ER diagrams: entities, relationships, roles and naming

Schema diagram (slide 26). **Bold** = underlined (the primary key). The last column lists the arrows (foreign key → referenced relation).
RelationAttributesArrows
takesID, course_id, sec_id, semester, year, grade
  • ID → student
  • course_id, sec_id, semester, year → section
studentID, name, dept_name, tot_creddept_name → department
sectioncourse_id, sec_id, semester, year, building, room_no, time_slot_id
  • course_id → course
  • building, room_no → classroom
coursecourse_id, title, dept_name, creditsdept_name → department
departmentdept_name, building, budgetلا تذكر الشرائح شيئًا هنا.
advisors_id, i_id
  • s_id → student
  • i_id → instructor
time_slottime_slot_id, day, start_time, end_timeلا تذكر الشرائح شيئًا هنا.
classroombuilding, room_no, capacityلا تذكر الشرائح شيئًا هنا.
prereqcourse_id, prereq_id
  • course_id → course
  • prereq_id → course
instructorID, name, dept_name, salarydept_name → department
teachesID, course_id, sec_id, semester, year
  • ID → instructor
  • course_id, sec_id, semester, year → section
تفاصيل المصدرالفصل 5.1 · الشريحة ⁦26⁩
المصدر
الفصل 5.1 · الشريحة ⁦26⁩

ER diagram basicsأساسيات المخطط

ER diagrams: entities, relationships, roles and naming

Entity Relationship Diagram (slide 29)

  • A graphical representation of entities and their relationships in a database structure.
  • Describes the conceptual database as viewed by the end user: entities, attributes (keys and non-key), relationships.

Naming conventions (slide 30)

  • Entity names: descriptive, familiar terminology, singular.
  • Attribute names: descriptive of the data; proper naming facilitates communication and promotes self-documentation.
  • All lowercase letters for the class assignments.
Rectangleمستطيل
An entity set; attributes listed inside; underline = primary key.
Diamondمعيّن
A relationship set.
Rolesالأدوار
Entity sets of a relationship need not be distinct; each occurrence plays a "role" — in prereq, "course_id" and "prereq_id" are roles.

The examples drawn on slides 31–34

  • Slide 31: the rectangles instructor (ID, name, salary) and student (ID, name, tot_cred), with ID underlined.
  • Slide 33: the diamond advisor joins the two rectangles by lines.
  • Slide 34 (relationship sets with attributes): the attribute date is drawn in a box joined to the advisor diamond by a dashed line.

prereq relates course to course. What are the labels "course_id" and "prereq_id" on its lines called?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦29, 30, 31, 33, 34, 35⁩
المصدر
الفصل 5.1 · الشرائح ⁦29, 30, 31, 33, 34, 35⁩

Summary of E-R symbolsملخص الرموز

ER diagrams: entities, relationships, roles and naming

The various symbols we use with the Peter Chen notation (slide 32)
SymbolالرمزMeaningالمعنى
RectangleEntity
Double rectangleWeak entity
DiamondRelationship
Double diamondIdentifying relationship
OvalAttribute
Oval with a solid line insideKey attribute
Oval with a dashed line insidePartial key, discriminator
Oval joined to smaller ovalsComposite attribute
Double ovalMultivalued attribute
Dotted ovalDerived attribute
Double lineTotal participation
1, 2, N, n, mCardinality expressions
Symbols used in E-R notation (slides 50, 83–84)
SymbolالرمزMeaningالمعنى
RectangleEntity set
DiamondRelationship set
Double rectangleWeak entity set
Double diamondIdentifying relationship set for a weak entity set
Double lineTotal participation of an entity set in a relationship
Solid underlinePrimary key
Dashed underlineDiscriminating attribute of a weak entity set
{A3} / A4()Multivalued attribute / derived attribute
l..h on a lineCardinality limits
Arrow (→) / line (—)One / many
Triangle (ISA)Generalization or specialization

In an E-R diagram, what does a double diamond represent?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦32, 50, 83, 84⁩
المصدر
الفصل 5.1 · الشرائح ⁦32, 50, 83, 84⁩

Total and partial participationالمشاركة

Participation and minimum cardinality

Minimum cardinality
The minimum number of entity instances that must participate in a relationship — generally 0 (partial / optional) or 1 (total / mandatory).

Total (mandatory)كلية

  • Indicated by a double line.
  • Every entity participates in at least one relationship.
  • Student in advisor: every student must have an associated instructor.

Partial (optional)جزئية

  • Some entities may not participate in any relationship.
  • Instructor in advisor: an instructor may advise no student.

Every student must have an associated instructor in advisor, but an instructor may advise no one. How are the participations described?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦41–42⁩
المصدر
الفصل 5.1 · الشرائح ⁦41–42⁩

Chen l..h and crow's foot notationChen وقدم الغراب

Participation and minimum cardinality

Chen notation l..h (slide 43)

  • l = minimum, h = maximum cardinality.
  • Minimum 1 → total participation; maximum 1 → at most one relationship; maximum * → no limit.
  • Example: an instructor can advise 0 or more students (0..*); a student must have 1 advisor and cannot have multiple advisors (1..1).

Crow's foot (slides 44–45)

  • Minimum 0 (optional): an oval next to the optional entity.
  • Minimum 1 (mandatory): a vertical hash mark next to the required entity.
  • Next to B, the symbol farther from B gives the minimum and the symbol touching B the maximum number of records of "B" that can be associated with one record of "A" (slide 45).

In Chen notation, a line carries the limits l..h. What does a minimum value of 1 indicate?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦43–45⁩
المصدر
الفصل 5.1 · الشرائح ⁦43–45⁩

Crow's foot symbols and examplesرموز قدم الغراب

Participation and minimum cardinality

Data modeling notation: crow's foot (slide 46)
SymbolالرمزMeaningالمعنىNumeric meaningالمعنى العددي
Two barsMandatory–OneExactly one
Bar and crow's footMandatory–ManyOne or more
Circle and barOptional–OneZero or one
Circle and crow's footOptional–ManyZero or more
Cardinalities in crow's foot notation (slide 45): the symbols at each end, read from the entity outward
CaseNext to ANext to B
(b) R is 1:Nbar, then circlecrow's foot, then bar
(c) R is 1:1bar, then barbar, then circle
(d) R is M:Ncrow's foot, then circlecrow's foot, then bar
The ERD notations (slide 36): Chen and crow's foot
RelationshipChenReading
One-to-Many (1:M)PAINTER 1 — paints — M PAINTING
  • a PAINTER can paint many PAINTINGs
  • each PAINTING is painted by one PAINTER
Many-to-Many (M:N)EMPLOYEE M — learns — N SKILL
  • an EMPLOYEE can learn many SKILLs
  • each SKILL can be learned by many EMPLOYEEs
One-to-One (1:1)EMPLOYEE 1 — manages — 1 STORE
  • an EMPLOYEE manages one STORE
  • each STORE is managed by one EMPLOYEE
  • Slide 47 — CLASS is optional to COURSE: COURSE (1,1) — generates — (0,N) CLASS; the CLASS end shows a circle with a crow's foot.

The invoicing problem (slide 49, Chen and crow's foot ERDs): this model may be read as follows

  • each CUSTOMER may generate one or more INVOICEs
  • each INVOICE is generated by one CUSTOMER
  • each INVOICE contains one or more invoice LINEs
  • each invoice LINE is contained in one INVOICE
تفاصيل المصدرالفصل 5.1 · الشرائح ⁦36, 45, 46, 47, 49⁩
المصدر
الفصل 5.1 · الشرائح ⁦36, 45, 46, 47, 49⁩

Entity sets to schemasالكيانات إلى جداول

Reduction to relation schemas

Reduction to relation schemas (slide 53)

  • Entity sets and relationship sets can be expressed uniformly as relation schemas that represent the contents of the database.
  • A database which conforms to an E-R diagram can be represented by a collection of schemas.
  • For each entity set and relationship set there is a unique schema that is assigned the name of the corresponding entity set or relationship set.
  • Each schema has a number of columns (generally corresponding to attributes), which have unique names.
Reduction to relation schemas (slides 54–57)
E-R constructالبنية في المخططRelation schemaالمخطط العلائقي
Strong entity setSame attributes: student(ID, name, tot_cred)
Weak entity setIncludes the primary key of the identifying strong entity set: section(course_id, sec_id, sem, year)
Composite attribute
  • Flattened: one attribute per component (name_first_name, name_last_name
  • prefix omitted if unambiguous)
Multivalued attribute M of ESeparate schema EM with the key of E and M: inst_phone(ID, phone_number)
  • Ignoring multivalued attributes, the extended instructor schema is: instructor(ID, first_name, middle_initial, last_name, street_number, street_name, apt_number, city, state, zip_code, date_of_birth) (slide 56).

المسألة

Instructor 22222 has phone numbers 456-7890 and 123-4567. What tuples go into inst_phone(ID, phone_number)? (slide 57)

المعطيات

inst_phone
(ID, phone_number)

Instructor 22222 has two phone numbers, 456-7890 and 123-4567. How many tuples does this give in inst_phone(ID, phone_number)?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦53, 54, 56, 57⁩
المصدر
الفصل 5.1 · الشرائح ⁦53, 54, 56, 57⁩

Relationship sets to schemasالعلاقات إلى جداول

Reduction to relation schemas

Many-to-many relationship set
A schema with the primary keys of the two participating entity sets and any descriptive attributes — advisor = (s_id, i_id).

Placing the foreign key (slides 58–60)

  • Many-to-one / one-to-many, total on the many-side: add to the "many" side an attribute holding the primary key of the "one" side — dept_name in instructor instead of a schema for inst_dept.
  • One-to-one: either side can act as the "many" side.
  • If participation is partial on the "many" side, the extra attribute could result in null values.
  • The schema of the relationship linking a weak entity set to its identifying strong entity set is redundant (section already contains sec_course's attributes).

inst_dept is many-to-one from instructor to department and total on the instructor side. Instead of a separate schema for inst_dept, what can be done?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦55, 58, 59, 60⁩
المصدر
الفصل 5.1 · الشرائح ⁦55, 58, 59, 60⁩

Non-binary relationshipsالعلاقات غير الثنائية

Non-binary relationship sets (slide 62)

  • Most relationship sets are binary; there are occasions when it is more convenient to represent relationships as non-binary — an E-R diagram with a ternary relationship: proj_guide joins instructor, student and project.

Cardinality on a ternary relationship (slide 63)

  • At most one arrow out of a ternary (or greater degree) relationship.
  • An arrow from proj_guide to instructor: each student has at most one guide for a project.
  • More than one arrow has two possible meanings, so we outlaw more than one arrow.

Binary vs non-binary (slide 79)

  • An n-ary relationship shows more clearly that several entities participate in a single relationship.
  • parents (child, father, mother) is best replaced by two binary relationships, father and mother — this allows partial information (e.g., only the mother known).
  • Some relationships are naturally non-binary: proj_guide.

Converting R(A, B, C) to binary form (slide 80)

  1. 1

    Replace R by an artificial entity set E and three relationship sets RA, RB, RC.

  2. 2

    Create an identifying attribute for E and add any attributes of R to E.

  3. 3

    For each (ai, bi, ci) in R: create entity ei, add (ei, ai) to RA, (ei, bi) to RB, (ei, ci) to RC.

Converting non-binary relationships (slide 81)

  • Also need to translate constraints: translating all constraints may not be possible; there may be instances in the translated schema that cannot correspond to any instance of R.
  • Exercise (slide): add constraints to the relationships RA, RB and RC to ensure that a newly created entity corresponds to exactly one entity in each of entity sets A, B and C.
  • We can avoid creating an identifying attribute by making E a weak entity set identified by the three relationship sets.
Three types of relationship degree in crow's foot notation (slide 64)
DegreeExample
UnaryEMPLOYEE manages EMPLOYEE
BinaryPROFESSOR teaches CLASS
Ternary (conceptual)DOCTOR, PATIENT and DRUG joined by prescribes
Ternary (logical)
  • DOCTOR writes PRESCRIPTION
  • PATIENT receives PRESCRIPTION
  • DRUG appears in PRESCRIPTION

Why is the ternary relationship parents (child, father, mother) best replaced by two binary relationships, father and mother?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦62, 63, 64, 79, 80, 81⁩
المصدر
الفصل 5.1 · الشرائح ⁦62, 63, 64, 79, 80, 81⁩

Specialization and generalizationالتخصيص والتعميم

Specialization, generalization and their constraints

Specializationالتخصيص

  • Top-down: designate sub-groupings within an entity set.
  • Sub-groupings become lower-level entity sets with their own attributes or relationships.

Generalizationالتعميم

  • Bottom-up: combine entity sets that share the same features into a higher-level entity set.
  • Specialization and generalization are simple inversions of each other, drawn the same way.
  • Depicted by a triangle labeled IS A (instructor "is a" person).
  • Attribute inheritance: a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set.
  • Slide 66: overlapping — employee and student; disjoint — instructor and secretary.
Specialization example (slide 66); the employee/student split is overlapping, the instructor/secretary split is disjoint

person (ID, name, street, city)

employee (salary)

instructor (rank)secretary (hours_per_week)
student (tot_credits)
  • Slide 66 also lists Partial (default) and Total.
  • The terms specialization and generalization are used interchangeably (slide 71).

Which design process is bottom-up, combining entity sets that share the same features into a higher-level entity set?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦65, 66, 71⁩
المصدر
الفصل 5.1 · الشرائح ⁦65, 66, 71⁩

Completeness and disjointness constraintsالاكتمال والتداخل

Specialization, generalization and their constraints

Partial completenessاكتمال جزئي
Not every supertype occurrence is a member of a subtype — the default.
Total completenessاكتمال كلي
Every supertype occurrence must be a member of at least one subtype (keyword total with a dashed line). E.g., every student is graduate or undergraduate.
Disjoint (d)منفصل
Each supertype instance appears in only one subtype; implemented with the value of a subtype discriminator attribute in the supertype.
Overlapping (O)متداخل
An instance may appear in more than one subtype; implementation requires one discriminator attribute for each subtype.

Slides 69–70

  • Partial generalization is the default.
  • Total generalization is specified by adding the keyword total in the diagram and drawing a dashed line from the keyword to the corresponding hollow arrow-head (for a total generalization), or to the set of hollow arrow-heads (for an overlapping generalization).
  • The student generalization is total: all student entities must be either graduate or undergraduate. Because the higher-level entity set arrived at through generalization is generally composed of only those entities in the lower-level entity sets, the completeness constraint for a generalized higher-level entity set is usually total.
  • Disjoint subtypes are also known as nonoverlapping subtypes (d) (slide 70).

A person can be both an employee and a student. Which subtypes are these, and how are they implemented?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦69–70⁩
المصدر
الفصل 5.1 · الشرائح ⁦69–70⁩

Specialization to schemasالتخصيص إلى جداول

Specialization, generalization and their constraints

Method 1الطريقة 1

  • A schema for the higher-level entity, and for each lower-level entity set: the higher-level primary key + local attributes.
  • person(ID, name, street, city); student(ID, tot_cred); employee(ID, salary).
  • Drawback: information about an employee requires accessing two relations.

Method 2الطريقة 2

  • A schema for each entity set with all local and inherited attributes.
  • student(ID, name, street, city, tot_cred); employee(ID, name, street, city, salary).
  • Drawback: name, street and city may be stored redundantly for people who are both students and employees.

Specialization is represented by person(ID, name, street, city), student(ID, tot_cred) and employee(ID, salary). What is the drawback?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦67–68⁩
المصدر
الفصل 5.1 · الشرائح ⁦67–68⁩

Aggregationالتجميع

Record evaluations of a student by a guide on a project. eval_for and proj_guide represent overlapping information: every eval_for corresponds to a proj_guide relationship, but some proj_guide relationships may not have any eval_for, so proj_guide cannot be discarded.

Aggregation
Treat the relationship as an abstract entity, allowing relationships between relationships — it eliminates the redundancy.
  • Slide 72: without aggregation, eval_for joins instructor, student, project and evaluation, beside proj_guide.
  • Aggregation: treat relationship as an abstract entity; allows relationships between relationships; abstraction of relationship into new entity (slide 73).
  • Slide 74: proj_guide with instructor, student and project is boxed as one unit, and eval_for joins that box to evaluation. It represents: a student is guided by a particular instructor on a particular project; a student, instructor, project combination may have an associated evaluation.

Schema (slide 75)

  • Primary key of the aggregated relationship + primary key of the associated entity set + descriptive attributes.
  • eval_for (s_ID, project_id, i_ID, evaluation_id); the schema proj_guide is redundant.

With aggregation, which schema represents the evaluation of a student by a guide on a project?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦72–75⁩
المصدر
الفصل 5.1 · الشرائح ⁦72–75⁩

Design issues and UMLقضايا التصميم وUML

Design issues, decisions and UML

E-R design decisions (slide 82)

  • The use of an attribute or entity set to represent an object.
  • Whether a real-world concept is best expressed by an entity set or a relationship set.
  • The use of a ternary relationship versus a pair of binary relationships.
  • The use of a strong or weak entity set.
  • The use of specialization/generalization — contributes to modularity in the design.
  • The use of aggregation — can treat the aggregate entity set as a single unit without concern for the details of its internal structure.
  • Entity vs. attribute: phone as an entity allows extra information about phone numbers, plus multiple numbers.
  • Entity vs. relationship set: use a relationship set to describe an action that occurs between entities; e.g., date as an attribute of advisor or of student.
  • Specialization/generalization contributes to modularity in the design.
  • Aggregation treats the aggregate entity set as a single unit without concern for its internal structure.

The design-issue diagrams (slides 77–78)

  • Slide 77: instructor (ID, name, salary, phone_number) versus instructor (ID, name, salary) — inst_phone — phone (phone_number, location).
  • Slide 78: section — section_reg — registration — student_reg — student; the slide also names placement of relationship attributes.

UML (slides 87–88)

  • UML: Unified Modeling Language, modelling an entire software system.
  • UML class diagrams correspond to E-R diagrams, with differences — note the reversal of position in the cardinality constraint depiction.
Alternative ER notations (slides 85–86): Chen, IDE1FX, …
ConceptChen-style (slide 85–86 left)Crow's-foot style (slide 86 right)
Entity set E with simple A1 (primary key), composite A2 (A2.1, A2.2), multivalued A3, derived A4ovals around E: A1 underlined, A2 with its own ovals, A3 double oval, A4 dashed ovalلا تذكر الشرائح شيئًا هنا.
Weak entity setdouble rectangleلا تذكر الشرائح شيئًا هنا.
Generalization / total generalizationtriangle ISA / triangle ISA with a double lineلا تذكر الشرائح شيئًا هنا.
Many-to-manyE1 * — R — * E2crow's feet at both ends
One-to-oneE1 1 — R — 1 E2plain line
Many-to-oneE1 * — R — 1 E2crow's foot at E1
Participation in R: total (E1) and partial (E2)double line at E1
  • crow's foot and circle at E1
  • bar and crow's foot at E2
ER vs. UML class diagrams (slides 88–89)
ER diagram notationEquivalent in UML
Entity with attributes (simple, composite, multivalued, derived)Class with simple attributes and methods (attribute prefixes: + = public, – = private, # = protected)
Binary relationship: E1 role1 — R — role2 E2E1 role1 — R — role2 E2 as a line
Relationship attributes: A1 attached to RA box R with A1, joined to the line by a dotted line
Cardinality constraints: E1 0..* — R — 0..1 E2E1 0..1 — R — 0..* E2 (note the reversal of position)
n-ary relationshipsdrawn with the diamond R as in ER
Overlapping generalizationseparate arrows with a dotted line labeled overlapping
Disjoint generalizationmerged arrow labeled disjoint
  • Generalization can use merged or separate arrows independent of disjoint/overlapping (slide 89).
  • UML has many components to graphically model different aspects of an entire software system (slide 87).

Which difference between E-R diagrams and UML class diagrams is noted?

تفاصيل المصدرالفصل 5.1 · الشرائح ⁦77, 78, 82, 85, 86, 87, 88, 89⁩
المصدر
الفصل 5.1 · الشرائح ⁦77, 78, 82, 85, 86, 87, 88, 89⁩

الخلاصة

تفاصيل المصدر
المصدر
الفصل 5.1

خريطة الفصل

    1. 1مقدمة الفصل
  1. Design phases and database design stepsمراحل التصميم وخطوات بناء القاعدة

    1. 2Design phasesمراحل التصميم
    1. 3Data models and the ER modelنموذج الكيان والعلاقة
  2. Entity sets and relationship setsمجموعات الكيانات والعلاقات

    1. 4Entity setsمجموعات الكيانات
    2. 5Relationship sets and degreeمجموعات العلاقات
    3. 6Example: instructor, student and advisorمثال advisor
  3. Mapping cardinality constraintsأنماط التعدد

    1. 7Mapping cardinalitiesأنماط التعدد
    2. 8Cardinality examples with advisorأمثلة التعدد
  4. Kinds of attributesأنواع الصفات

    1. 9Kinds of attributesأنواع الصفات
    2. 10Drawing complex attributesرسم الصفات
  5. Existence dependence and weak entitiesالاعتماد في الوجود والكيانات الضعيفة

    1. 11Existence dependence and weak entitiesالكيان الضعيف
    2. 12A weak entity: EMPLOYEE has DEPENDENTمثال الكيان الضعيف
  6. ER diagrams: entities, relationships, roles and namingمخطط الكيان والعلاقة: الرموز والأدوار والتسمية

    1. 13The university design: entity sets and relationship setsتصميم الجامعة
    2. 14The university schema diagramمخطط الجامعة
    3. 15ER diagram basicsأساسيات المخطط
    4. 16Summary of E-R symbolsملخص الرموز
  7. Participation and minimum cardinalityالمشاركة والحد الأدنى للتعدد

    1. 17Total and partial participationالمشاركة
    2. 18Chen l..h and crow's foot notationChen وقدم الغراب
    3. 19Crow's foot symbols and examplesرموز قدم الغراب
  8. Reduction to relation schemasالتحويل إلى مخططات علاقات

    1. 20Entity sets to schemasالكيانات إلى جداول
    2. 21Relationship sets to schemasالعلاقات إلى جداول
    1. 22Non-binary relationshipsالعلاقات غير الثنائية
  9. Specialization, generalization and their constraintsالتخصيص والتعميم وقيودهما

    1. 23Specialization and generalizationالتخصيص والتعميم
    2. 24Completeness and disjointness constraintsالاكتمال والتداخل
    3. 25Specialization to schemasالتخصيص إلى جداول
    1. 26Aggregationالتجميع
  10. Design issues, decisions and UMLقضايا التصميم وقراراته وUML

    1. 27Design issues and UMLقضايا التصميم وUML
    1. 28الخلاصة