Entity Relationship Model (CommenteD)

download Entity Relationship Model (CommenteD)

of 82

Transcript of Entity Relationship Model (CommenteD)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    1/82

    Database System Concepts, 5th Ed.

    Silberschatz, Korth and Sudarshan

    See www.db-book.com for conditions on re-use

    Chapter 6: Entity-Relationship ModelChapter 6: Entity-Relationship Model

    http://www.db-book.com/http://www.db-book.com/
  • 8/14/2019 Entity Relationship Model (CommenteD)

    2/82

    Silberschatz, Korth and Sudarshan6.2Database System Concepts - 5th Edition, July 11, 2005

    Chapter 6: Entity-Relationship ModelChapter 6: Entity-Relationship Model

    s Design Process

    s Modeling

    s Constraints

    s E-R Diagram

    s Design Issues

    s Weak Entity Sets

    s Extended E-R Features

    s Design of the Bank Database

    s Reduction to Relation Schemas

    s Database Designs UML

  • 8/14/2019 Entity Relationship Model (CommenteD)

    3/82

    Silberschatz, Korth and Sudarshan6.3Database System Concepts - 5th Edition, July 11, 2005

    ModelingModeling

    s A databasecan be modeled as:

    q a collection of entities,

    q relationship among entities.

    s An entityis an object that exists and is distinguishable from otherobjects.

    q Example: specific person, company, event, plants Entities have attributes

    q Example: people have namesand addresses

    s An entity set is a set of entities of the same type that share the sameproperties.

    q Example: set of all persons, companies, trees, holidays

  • 8/14/2019 Entity Relationship Model (CommenteD)

    4/82

    Silberschatz, Korth and Sudarshan6.4Database System Concepts - 5th Edition, July 11, 2005

    Entity SetsEntity Sets customercustomerandand loanloan

    customer_id customer_ customer_ customer_ loan_ amountname street city number

  • 8/14/2019 Entity Relationship Model (CommenteD)

    5/82

    Silberschatz, Korth and Sudarshan6.5Database System Concepts - 5th Edition, July 11, 2005

    Relationship SetsRelationship Sets

    s A relationship is an association among several entities

    Example:Hayes depositor A-102

    customerentity relationship set accountentity

    s A relationship set is a mathematical relation among n 2 entities,each taken from entity sets

    {(e1, e

    2, e

    n) | e

    1 E

    1, e

    2 E

    2, , e

    n E

    n}

    where (e1, e

    2, , e

    n) is a relationship

    q Example:

    (Hayes, A-102)

    depositor

  • 8/14/2019 Entity Relationship Model (CommenteD)

    6/82

    Silberschatz, Korth and Sudarshan6.6Database System Concepts - 5th Edition, July 11, 2005

    Relationship SetRelationship Set borrowerborrower

  • 8/14/2019 Entity Relationship Model (CommenteD)

    7/82Silberschatz, Korth and Sudarshan6.7Database System Concepts - 5th Edition, July 11, 2005

    Relationship Sets (Cont.)Relationship Sets (Cont.)

    s An attribute can also be property of a relationship set.

    s For instance, the depositorrelationship set between entity sets customerand accountmay have the attribute access-date

  • 8/14/2019 Entity Relationship Model (CommenteD)

    8/82Silberschatz, Korth and Sudarshan6.8Database System Concepts - 5th Edition, July 11, 2005

    Degree of a Relationship SetDegree of a Relationship Set

    s Refers to number of entity sets that participate in a relationship

    set.

    s Relationship sets that involve two entity sets are binary (ordegree two). Generally, most relationship sets in a databasesystem are binary.

    s Relationship sets may involve more than two entity sets.

    s Relationships between more than two entity sets are rare. Mostrelationships are binary. (More on this later.)

    Example: Suppose employees of a bank may have jobs(responsibilities) at multiple branches, with different jobs atdifferent branches. Then there is a ternary relationship setbetween entity sets employee, job, and branch

  • 8/14/2019 Entity Relationship Model (CommenteD)

    9/82Silberschatz, Korth and Sudarshan6.9Database System Concepts - 5th Edition, July 11, 2005

    AttributesAttributes

    s An entity is represented by a set of attributes, that is descriptive

    properties possessed by all members of an entity set.

    s Domain the set of permitted values for each attribute

    s Attribute types:

    q Simpleand compositeattributes.

    q Single-valuedand multi-valuedattributes

    Example: multivalued attribute: phone_numbers

    q Derivedattributes

    Can be computed from other attributes

    Example: age, given date_of_birth

    Example:

    customer =(customer_id, customer_name,customer_street, customer_city)

    loan =(loan_number, amount)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    10/82Silberschatz, Korth and Sudarshan6.10Database System Concepts - 5th Edition, July 11, 2005

    Composite AttributesComposite Attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    11/82Silberschatz, Korth and Sudarshan6.11Database System Concepts - 5th Edition, July 11, 2005

    Mapping Cardinality ConstraintsMapping Cardinality Constraints

    s Express the number of entities to which another entity can be

    associated via a relationship set.

    s Most useful in describing binary relationship sets.

    s For a binary relationship set the mapping cardinality must be one ofthe following types:

    q One to one

    q One to many

    q Many to one

    q Many to many

  • 8/14/2019 Entity Relationship Model (CommenteD)

    12/82Silberschatz, Korth and Sudarshan6.12Database System Concepts - 5th Edition, July 11, 2005

    Mapping CardinalitiesMapping Cardinalities

    One to one One to many

    Note: Some elements in A and Bmay not be mapped to anyelements in the other set

  • 8/14/2019 Entity Relationship Model (CommenteD)

    13/82Silberschatz, Korth and Sudarshan6.13Database System Concepts - 5th Edition, July 11, 2005

    Mapping CardinalitiesMapping Cardinalities

    Many to one Many to many

    Note: Some elements in A and B may not be mapped to anyelements in the other set

  • 8/14/2019 Entity Relationship Model (CommenteD)

    14/82Silberschatz, Korth and Sudarshan6.14Database System Concepts - 5th Edition, July 11, 2005

    KeysKeys

    s A super key of an entity set is a set of one or more attributes

    whose values uniquely determine each entity.

    s A candidate key of an entity set is a minimal super key

    q Customer_idis candidate key of customer

    q account_numberis candidate key of account

    s Although several candidate keys may exist, one of the candidatekeys is selected to be the primary key.

  • 8/14/2019 Entity Relationship Model (CommenteD)

    15/82Silberschatz, Korth and Sudarshan6.15Database System Concepts - 5th Edition, July 11, 2005

    Keys for Relationship SetsKeys for Relationship Sets

    s The combination of primary keys of the participating entity sets forms a

    super key of a relationship set.

    q (customer_id, account_number) is the super key of depositor

    q NOTE: this means a pair of entity sets can have at most onerelationship in a particular relationship set.

    Example: if we wish to track all access_dates to each account byeach customer, we cannot assume a relationship for eachaccess. We can use a multivalued attribute though

    s Must consider the mapping cardinality of the relationship set whendeciding the what are the candidate keys

    s Need to consider semantics of relationship set in selecting the primarykey in case of more than one candidate key

  • 8/14/2019 Entity Relationship Model (CommenteD)

    16/82Silberschatz, Korth and Sudarshan6.16Database System Concepts - 5th Edition, July 11, 2005

    E-R DiagramsE-R Diagrams

    s Rectangles represent entity sets.

    s Diamonds represent relationship sets.

    s Lines link attributes to entity sets and entity sets to relationship sets.

    s Ellipses represent attributesq Double ellipses represent multivalued attributes.

    q Dashed ellipses denote derived attributes.

    s Underline indicates primary key attributes (will study later)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    17/82Silberschatz, Korth and Sudarshan6.17Database System Concepts - 5th Edition, July 11, 2005

    E-R Diagram With Composite, Multivalued, andE-R Diagram With Composite, Multivalued, and

    Derived AttributesDerived Attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    18/82Silberschatz, Korth and Sudarshan6.18Database System Concepts - 5th Edition, July 11, 2005

    Relationship Sets with AttributesRelationship Sets with Attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    19/82Silberschatz, Korth and Sudarshan6.19Database System Concepts - 5th Edition, July 11, 2005

    RolesRoles

    s Entity sets of a relationship need not be distinct

    s The labels manager and worker are called roles; they specify howemployee entities interact via the works_for relationship set.

    s Roles are indicated in E-R diagrams by labeling the lines that connectdiamonds to rectangles.

    s Role labels are optional, and are used to clarify semantics of therelationship

  • 8/14/2019 Entity Relationship Model (CommenteD)

    20/82Silberschatz, Korth and Sudarshan6.20Database System Concepts - 5th Edition, July 11, 2005

    Cardinality ConstraintsCardinality Constraints

    s We express cardinality constraints by drawing either a directed line (),

    signifying one, or an undirected line (), signifying many, betweenthe relationship set and the entity set.

    s One-to-one relationship:

    q A customer is associated with at most one loan via the relationshipborrower

    q A loan is associated with at most one customer via borrower

  • 8/14/2019 Entity Relationship Model (CommenteD)

    21/82Silberschatz, Korth and Sudarshan6.21Database System Concepts - 5th Edition, July 11, 2005

    One-To-Many RelationshipOne-To-Many Relationship

    s In the one-to-many relationship a loan is associated with at most one

    customer via borrower, a customer is associated with several (including0) loans via borrower

    M T O R l i hi

  • 8/14/2019 Entity Relationship Model (CommenteD)

    22/82Silberschatz, Korth and Sudarshan6.22Database System Concepts - 5th Edition, July 11, 2005

    Many-To-One RelationshipsMany-To-One Relationships

    s In a many-to-one relationship a loan is associated with several (including

    0) customers via borrower, a customer is associated with at most oneloan via borrower

  • 8/14/2019 Entity Relationship Model (CommenteD)

    23/82Silberschatz, Korth and Sudarshan6.23Database System Concepts - 5th Edition, July 11, 2005

    Many-To-Many RelationshipMany-To-Many Relationship

    s A customer is associated with several (possibly 0) loans via

    borrower

    s A loan is associated with several (possibly 0) customers viaborrower

    Participation of an Entity Set in aParticipation of an Entity Set in a

  • 8/14/2019 Entity Relationship Model (CommenteD)

    24/82

    Silberschatz, Korth and Sudarshan6.24Database System Concepts - 5th Edition, July 11, 2005

    Participation of an Entity Set in aParticipation of an Entity Set in a

    Relationship SetRelationship Set

    s Total participation (indicated by double line): every entity in the entity set

    participates in at least one relationship in the relationship set

    q E.g. participation of loan in borrower is total

    every loan must have a customer associated to it via borrower

    s Partial participation: some entities may not participate in any relationship inthe relationship set

    q Example: participation of customer in borrower is partial

  • 8/14/2019 Entity Relationship Model (CommenteD)

    25/82

    Silberschatz, Korth and Sudarshan6.25Database System Concepts - 5th Edition, July 11, 2005

    Alternative Notation for Cardinality LimitsAlternative Notation for Cardinality Limits

    s Cardinality limits can also express participation constraints

  • 8/14/2019 Entity Relationship Model (CommenteD)

    26/82

    Silberschatz, Korth and Sudarshan6.26Database System Concepts - 5th Edition, July 11, 2005

    E-RE-R Diagram with a Ternary RelationshipDiagram with a Ternary Relationship

    C di lit C t i t TC di lit C t i t T

  • 8/14/2019 Entity Relationship Model (CommenteD)

    27/82

    Silberschatz, Korth and Sudarshan6.27Database System Concepts - 5th Edition, July 11, 2005

    Cardinality Constraints on TernaryCardinality Constraints on Ternary

    RelationshipRelationship

    s We allow at most one arrow out of a ternary (or greater degree) relationship

    to indicate a cardinality constraint

    s E.g. an arrow from works_onto jobindicates each employee works on atmost one job at any branch.

    s If there is more than one arrow, there are two ways of defining the meaning.

    q E.g a ternary relationship Rbetween A, Band Cwith arrows to Band Ccould mean

    1. each A entity is associated with a unique entity from Band Cor

    2. each pair of entities from (A, B) is associated with a unique Centity,and each pair (A, C) is associated with a unique B

    q

    Each alternative has been used in different formalismsq To avoid confusion we outlaw more than one arrow

  • 8/14/2019 Entity Relationship Model (CommenteD)

    28/82

    Silberschatz, Korth and Sudarshan6.28Database System Concepts - 5th Edition, July 11, 2005

    Design IssuesDesign Issues

    s Use of entity sets vs. attributes

    Choice mainly depends on the structure of the enterprise beingmodeled, and on the semantics associated with the attribute inquestion.

    s Use of entity sets vs. relationship setsPossible guideline is to designate a relationship set to describe an

    action that occurs between entitiess Binary versus n-ary relationship sets

    Although it is possible to replace any nonbinary (n-ary, for n> 2)relationship set by a number of distinct binary relationship sets, an-ary relationship set shows more clearly that several entitiesparticipate in a single relationship.

    s Placement of relationship attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    29/82

    Silberschatz, Korth and Sudarshan6.29Database System Concepts - 5th Edition, July 11, 2005

    Binary Vs. Non-Binary RelationshipsBinary Vs. Non-Binary Relationships

    s Some relationships that appear to be non-binary may be better

    represented using binary relationships

    q E.g. A ternary relationship parents, relating a child to his/her fatherand mother, is best replaced by two binary relationships, fatherand mother

    Using two binary relationships allows partial information (e.g.

    only mother being know)q But there are some relationships that are naturally non-binary

    Example: works_on

    Converting Non Binary Relationships toConverting Non Binary Relationships to

  • 8/14/2019 Entity Relationship Model (CommenteD)

    30/82

    Silberschatz, Korth and Sudarshan6.30Database System Concepts - 5th Edition, July 11, 2005

    Converting Non-Binary Relationships toConverting Non-Binary Relationships to

    Binary FormBinary Form

    s In general, any non-binary relationship can be represented using binary relationships by

    creating an artificial entity set.q Replace Rbetween entity sets A, B and Cby an entity set E, and three relationship

    sets:

    1. RA, relating Eand A 2.RB, relating Eand B

    3. RC, relating Eand C

    q Create a special identifying attribute for Eq Add any attributes of Rto E

    q For each relationship (ai , bi , ci) in R, create

    1. a new entity eiin the entity set E 2. add (ei , ai) to RA

    3. add (ei , bi) to RB 4. add (ei , ci) to RC

    Converting Non Binary RelationshipsConverting Non Binary Relationships

  • 8/14/2019 Entity Relationship Model (CommenteD)

    31/82

    Silberschatz, Korth and Sudarshan6.31Database System Concepts - 5th Edition, July 11, 2005

    Converting Non-Binary RelationshipsConverting Non-Binary Relationships

    (Cont.)(Cont.)

    s Also need to translate constraints

    q Translating all constraints may not be possible

    q There may be instances in the translated schema thatcannot correspond to any instance of R

    Exercise: add constraints to the relationships RA, R

    Band

    RCto ensure that a newly created entity corresponds to

    exactly one entity in each of entity sets A, Band C

    q We can avoid creating an identifying attribute by making E aweak entity set (described shortly) identified by the threerelationship sets

  • 8/14/2019 Entity Relationship Model (CommenteD)

    32/82

    Silberschatz, Korth and Sudarshan6.32Database System Concepts - 5th Edition, July 11, 2005

    Mapping Cardinalities affect ER DesignMapping Cardinalities affect ER Design

    s Can make access-date an attribute of account, instead of a relationship

    attribute, if each account can have only one customer

    q That is, the relationship from account to customer is many to one, orequivalently, customer to account is one to many

  • 8/14/2019 Entity Relationship Model (CommenteD)

    33/82

    Database System Concepts, 5th Ed.

    Silberschatz, Korth and SudarshanSee www.db-book.com for conditions on re-use

    How about doing an ER designHow about doing an ER design

    interactively on the board?interactively on the board?

    Suggest an application to be modeled.Suggest an application to be modeled.

    http://www.db-book.com/http://www.db-book.com/
  • 8/14/2019 Entity Relationship Model (CommenteD)

    34/82

    Silberschatz, Korth and Sudarshan6.34Database System Concepts - 5th Edition, July 11, 2005

    Weak Entity SetsWeak Entity Sets

    s An entity set that does not have a primary key is referred to as a weak

    entity set.

    s The existence of a weak entity set depends on the existence of aidentifying entity set

    q it must relate to the identifying entity set via a total, one-to-manyrelationship set from the identifying to the weak entity set

    q Identifying relationship depicted using a double diamond

    s The discriminator(or partial key) of a weak entity set is the set ofattributes that distinguishes among all the entities of a weak entity set.

    s The primary key of a weak entity set is formed by the primary key of thestrong entity set on which the weak entity set is existence dependent,

    plus the weak entity sets discriminator.

  • 8/14/2019 Entity Relationship Model (CommenteD)

    35/82

  • 8/14/2019 Entity Relationship Model (CommenteD)

    36/82

    Silberschatz, Korth and Sudarshan6.36Database System Concepts - 5th Edition, July 11, 2005

    Weak Entity Sets (Cont.)Weak Entity Sets (Cont.)

    s Note: the primary key of the strong entity set is not explicitly stored

    with the weak entity set, since it is implicit in the identifyingrelationship.

    s If loan_numberwere explicitly stored, paymentcould be made astrong entity, but then the relationship between paymentand loanwould be duplicated by an implicit relationship defined by the

    attribute loan_numbercommon to paymentand loan

  • 8/14/2019 Entity Relationship Model (CommenteD)

    37/82

    Silberschatz, Korth and Sudarshan6.37Database System Concepts - 5th Edition, July 11, 2005

    More Weak Entity Set ExamplesMore Weak Entity Set Examples

    s In a university, a courseis a strong entity and a course_offeringcan

    be modeled as a weak entity

    s The discriminator of course_offeringwould be semester(includingyear) and section_number(if there is more than one section)

    s If we model course_offeringas a strong entity we would modelcourse_numberas an attribute.

    Then the relationship with coursewould be implicit in thecourse_numberattribute

    E d d E R F S i li i

  • 8/14/2019 Entity Relationship Model (CommenteD)

    38/82

    Silberschatz, Korth and Sudarshan6.38Database System Concepts - 5th Edition, July 11, 2005

    Extended E-R Features: SpecializationExtended E-R Features: Specialization

    s Top-down design process; we designate subgroupings within an entity set

    that are distinctive from other entities in the set.

    s These subgroupings become lower-level entity sets that have attributes orparticipate in relationships that do not apply to the higher-level entity set.

    s Depicted by a trianglecomponent labeled ISA (E.g. customeris aperson).

    s Attribute inheritance a lower-level entity set inherits all the attributesand relationship participation of the higher-level entity set to which it islinked.

    S i li i E l

  • 8/14/2019 Entity Relationship Model (CommenteD)

    39/82

    Silberschatz, Korth and Sudarshan6.39Database System Concepts - 5th Edition, July 11, 2005

    Specialization ExampleSpecialization Example

    E d d ER F G li iE d d ER F G li i

  • 8/14/2019 Entity Relationship Model (CommenteD)

    40/82

    Silberschatz, Korth and Sudarshan6.40Database System Concepts - 5th Edition, July 11, 2005

    Extended ER Features: GeneralizationExtended ER Features: Generalization

    s A bottom-up design process combine a number of entity sets

    that share the same features into a higher-level entity set.s Specialization and generalization are simple inversions of each

    other; they are represented in an E-R diagram in the same way.

    s The terms specialization and generalization are usedinterchangeably.

    S i li ti d G li ti (C t )S i li ti d G li ti (C t )

  • 8/14/2019 Entity Relationship Model (CommenteD)

    41/82

    Silberschatz, Korth and Sudarshan6.41Database System Concepts - 5th Edition, July 11, 2005

    Specialization and Generalization (Cont.)Specialization and Generalization (Cont.)

    s Can have multiple specializations of an entity set based on different

    features.s E.g. permanent_employeevs. temporary_employee, in addition to

    officer vs. secretaryvs. teller

    s Each particular employee would be

    q a member of one of permanent_employeeor temporary_employee,

    q and also a member of one of officer, secretary, or teller

    s The ISA relationship also referred to as superclass - subclassrelationship

    Design Constraints on aDesign Constraints on a

  • 8/14/2019 Entity Relationship Model (CommenteD)

    42/82

    Silberschatz, Korth and Sudarshan6.42Database System Concepts - 5th Edition, July 11, 2005

    Design Constraints on aDesign Constraints on a

    Specialization/GeneralizationSpecialization/Generalization

    s Constraint on which entities can be members of a given lower-level

    entity set.q condition-defined

    Example: all customers over 65 years are members of senior-citizenentity set; senior-citizenISA person.

    q user-defined

    s Constraint on whether or not entities may belong to more than onelower-level entity set within a single generalization.

    q Disjoint

    an entity can belong to only one lower-level entity set

    Noted in E-R diagram by writing disjointnext to the ISAtriangle

    q Overlapping

    an entity can belong to more than one lower-level entity set

    DesignDesign ConstraintsConstraints on aon a

  • 8/14/2019 Entity Relationship Model (CommenteD)

    43/82

    Silberschatz, Korth and Sudarshan6.43Database System Concepts - 5th Edition, July 11, 2005

    DesignDesignConstraintsConstraintson aon aSpecialization/Generalization (Cont.)Specialization/Generalization (Cont.)

    s Completenessconstraint -- specifies whether or not an entity

    in the higher-level entity set must belong to at least one of thelower-level entity sets within a generalization.

    q total: an entity must belong to one of the lower-level entitysets

    q partial: an entity need not belong to one of the lower-level

    entity sets

    A tiA ti

  • 8/14/2019 Entity Relationship Model (CommenteD)

    44/82

    Silberschatz, Korth and Sudarshan6.44Database System Concepts - 5th Edition, July 11, 2005

    AggregationAggregation

    s Consider the ternary relationship works_on, which we saw earlier

    s Suppose we want to record managers for tasks performed by anemployee at a branch

    A ti (C t )A ti (C t )

  • 8/14/2019 Entity Relationship Model (CommenteD)

    45/82

    Silberschatz, Korth and Sudarshan6.45Database System Concepts - 5th Edition, July 11, 2005

    Aggregation (Cont.)Aggregation (Cont.)

    s Relationship sets works_onand managesrepresent overlapping information

    q Every managesrelationship corresponds to a works_onrelationship

    q However, some works_onrelationships may not correspond to anymanagesrelationships

    So we cant discard the works_onrelationship

    s

    Eliminate this redundancy via aggregationq Treat relationship as an abstract entity

    q Allows relationships between relationships

    q Abstraction of relationship into new entity

    s Without introducing redundancy, the following diagram represents:

    q An employee works on a particular job at a particular branch

    q An employee, branch, job combination may have an associated manager

    E R Di With A tiE R Di With A ti

  • 8/14/2019 Entity Relationship Model (CommenteD)

    46/82

    Silberschatz, Korth and Sudarshan6.46Database System Concepts - 5th Edition, July 11, 2005

    E-R Diagram With AggregationE-R Diagram With Aggregation

    E R D i D i iE R Design Decisions

  • 8/14/2019 Entity Relationship Model (CommenteD)

    47/82

    Silberschatz, Korth and Sudarshan6.47Database System Concepts - 5th Edition, July 11, 2005

    E-R Design DecisionsE-R Design Decisions

    s The use of an attribute or entity set to represent an object.

    s Whether a real-world concept is best expressed by an entity set ora relationship set.

    s The use of a ternary relationship versus a pair of binaryrelationships.

    s The use of a strong or weak entity set.

    s The use of specialization/generalization contributes to modularityin the design.

    s The use of aggregation can treat the aggregate entity set as asingle unit without concern for the details of its internal structure.

    E R Diagram for a Banking EnterpriseE R Diagram for a Banking Enterprise

  • 8/14/2019 Entity Relationship Model (CommenteD)

    48/82

    Silberschatz, Korth and Sudarshan6.48Database System Concepts - 5th Edition, July 11, 2005

    E-R Diagram for a Banking EnterpriseE-R Diagram for a Banking Enterprise

  • 8/14/2019 Entity Relationship Model (CommenteD)

    49/82

    Database System Concepts, 5th Ed.

    Silberschatz, Korth and SudarshanSee www.db-book.com for conditions on re-use

    How about doing another ER designHow about doing another ER design

    interactively on the board?interactively on the board?

    Summary of Symbols Used in E R NotationSummary of Symbols Used in E R Notation

    http://www.db-book.com/http://www.db-book.com/
  • 8/14/2019 Entity Relationship Model (CommenteD)

    50/82

    Silberschatz, Korth and Sudarshan6.50Database System Concepts - 5th Edition, July 11, 2005

    Summary of Symbols Used in E-R NotationSummary of Symbols Used in E-R Notation

  • 8/14/2019 Entity Relationship Model (CommenteD)

    51/82

    Reduction to Relation SchemasReduction to Relation Schemas

  • 8/14/2019 Entity Relationship Model (CommenteD)

    52/82

    Silberschatz, Korth and Sudarshan6.52Database System Concepts - 5th Edition, July 11, 2005

    Reduction to Relation SchemasReduction to Relation Schemas

    s Primary keys allow entity sets and relationship sets to be

    expressed uniformly as relation schemasthat represent thecontents of the database.

    s A database which conforms to an E-R diagram can berepresented by a collection of schemas.

    s For each entity set and relationship set there is a unique

    schema that is assigned the name of the corresponding entityset or relationship set.

    s Each schema has a number of columns (generallycorresponding to attributes), which have unique names.

    Representing Entity Sets as SchemasRepresenting Entity Sets as Schemas

  • 8/14/2019 Entity Relationship Model (CommenteD)

    53/82

    Silberschatz, Korth and Sudarshan6.53Database System Concepts - 5th Edition, July 11, 2005

    Representing Entity Sets as SchemasRepresenting Entity Sets as Schemas

    s A strong entity set reduces to a schema with the same attributes.

    s A weak entity set becomes a table that includes a column for theprimary key of the identifying strong entity set

    payment =

    ( loan_number, payment_number, payment_date, payment_amount)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    54/82

    Redundancy of SchemasRedundancy of Schemas

  • 8/14/2019 Entity Relationship Model (CommenteD)

    55/82

    Silberschatz, Korth and Sudarshan6.55Database System Concepts - 5th Edition, July 11, 2005

    Redundancy of SchemasRedundancy of Schemas

    s Many-to-one and one-to-many relationship sets that are total on the

    many-side can be represented by adding an extra attribute to themany side, containing the primary key of the one side

    s Example: Instead of creating a schema for relationship setaccount_branch, add an attribute branch_nameto the schemaarising from entity set account

    Redundancy of Schemas (Cont )Redundancy of Schemas (Cont )

  • 8/14/2019 Entity Relationship Model (CommenteD)

    56/82

    Silberschatz, Korth and Sudarshan6.56Database System Concepts - 5th Edition, July 11, 2005

    Redundancy of Schemas (Cont.)Redundancy of Schemas (Cont.)

    s For one-to-one relationship sets, either side can be chosen to act as the

    many sideq That is, extra attribute can be added to either of the tables

    corresponding to the two entity sets

    s If participation is partialon the many side, replacing a schema by anextra attribute in the schema corresponding to the many side couldresult in null values

    s The schema corresponding to a relationship set linking a weak entity setto its identifying strong entity set is redundant.

    q Example: The paymentschema already contains the attributes thatwould appear in the loan_paymentschema (i.e., loan_numberandpayment_number).

    Composite and Multivalued AttributesComposite and Multivalued Attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    57/82

    Silberschatz, Korth and Sudarshan6.57Database System Concepts - 5th Edition, July 11, 2005

    Composite and Multivalued AttributesComposite and Multivalued Attributes

    s Composite attributes are flattened out by creating a separate attribute foreach component attribute

    q Example: given entity set customer with composite attribute namewithcomponent attributes first_nameand last_namethe schemacorresponding to the entity set has two attributes name.first_name and name.last_name

    s A multivalued attribute Mof an entity Eis represented by a separate

    schema EMq Schema EMhas attributes corresponding to the primary key of Eand

    an attribute corresponding to multivalued attribute M

    q Example: Multivalued attribute dependent_namesof employeeisrepresented by a schema: employee_dependent_names =( employee_id, dname)

    q Each value of the multivalued attribute maps to a separate tuple of therelation on schema EM

    For example, an employee entity with primary key 123-45-6789and dependents Jack and Jane maps to two tuples:

    (123-45-6789 , Jack) and (123-45-6789 , Jane)

    Representing Specialization viaRepresenting Specialization via

  • 8/14/2019 Entity Relationship Model (CommenteD)

    58/82

    Silberschatz, Korth and Sudarshan6.58Database System Concepts - 5th Edition, July 11, 2005

    Representing Specialization viaRepresenting Specialization via

    SchemasSchemass Method 1:

    q Form a schema for the higher-level entity

    q Form a schema for each lower-level entity set, include primarykey of higher-level entity set and local attributes

    schema attributes

    person name, street, city customer name, credit_ratingemployee name, salary

    q Drawback: getting information about, an employeerequiresaccessing two relations, the one corresponding to the low-levelschema and the one corresponding to the high-level schema

    Representing Specialization as SchemasRepresenting Specialization as Schemas

  • 8/14/2019 Entity Relationship Model (CommenteD)

    59/82

    Silberschatz, Korth and Sudarshan6.59Database System Concepts - 5th Edition, July 11, 2005

    p g pp g p

    (Cont.)(Cont.)

    s Method 2:

    q Form a schema for each entity set with all local and inherited attributes

    schema attributesperson name, street, city customer name, street, city, credit_ratingemployee name, street, city, salary

    q If specialization is total, the schema for the generalized entity set (person)not required to store information

    Can be defined as a view relation containing union of specializationrelations

    But explicit schema may still be needed for foreign key constraints

    q Drawback: streetand citymay be stored redundantly for people who areboth customers and employees

    Schemas Corresponding to AggregationSchemas Corresponding to Aggregation

  • 8/14/2019 Entity Relationship Model (CommenteD)

    60/82

    Silberschatz, Korth and Sudarshan6.60Database System Concepts - 5th Edition, July 11, 2005

    Schemas Corresponding to AggregationSchemas Corresponding to Aggregation

    s To represent aggregation, create a schema containing

    q primary key of the aggregated relationship,

    q the primary key of the associated entity set

    q any descriptive attributes

  • 8/14/2019 Entity Relationship Model (CommenteD)

    61/82

    UMLUML

  • 8/14/2019 Entity Relationship Model (CommenteD)

    62/82

    Silberschatz, Korth and Sudarshan6.62Database System Concepts - 5th Edition, July 11, 2005

    UMLUML

    s UML: Unified Modeling Language

    s UML has many components to graphically model different aspects of anentire software system

    s UML Class Diagrams correspond to E-R Diagram, but severaldifferences.

    Summary of UML Class Diagram NotationSummary of UML Class Diagram Notation

  • 8/14/2019 Entity Relationship Model (CommenteD)

    63/82

    Silberschatz, Korth and Sudarshan6.63Database System Concepts - 5th Edition, July 11, 2005

    y gy g

    UML Class Diagrams (Cont )UML Class Diagrams (Cont )

  • 8/14/2019 Entity Relationship Model (CommenteD)

    64/82

    Silberschatz, Korth and Sudarshan6.64Database System Concepts - 5th Edition, July 11, 2005

    UML Class Diagrams (Cont.)UML Class Diagrams (Cont.)

    s Entity sets are shown as boxes, and attributes are shown within the

    box, rather than as separate ellipses in E-R diagrams.s Binary relationship sets are represented in UML by just drawing a line

    connecting the entity sets. The relationship set name is written adjacentto the line.

    s The role played by an entity set in a relationship set may also be

    specified by writing the role name on the line, adjacent to the entity set.s The relationship set name may alternatively be written in a box, along

    with attributes of the relationship set, and the box is connected, using adotted line, to the line depicting the relationship set.

    s Non-binary relationships drawn using diamonds, just as in ER

    diagrams

    UML Class Diagram Notation (Cont.)UML Class Diagram Notation (Cont.)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    65/82

    Silberschatz, Korth and Sudarshan6.65Database System Concepts - 5th Edition, July 11, 2005

    UML Class Diagram Notation (Cont.)UML Class Diagram Notation (Cont.)

    *Note reversal of position in cardinality constraint depiction*Generalization can use merged or separate arrows independentof disjoint/overlapping

    overlapping

    disjoint

    UML Class Diagrams (Contd.)UML Class Diagrams (Contd.)

  • 8/14/2019 Entity Relationship Model (CommenteD)

    66/82

    Silberschatz, Korth and Sudarshan6.66Database System Concepts - 5th Edition, July 11, 2005

    UML Class Diagrams (Contd.)UML Class Diagrams (Contd.)

    s Cardinality constraints are specified in the form l..h, where l

    denotes the minimum and hthe maximum number ofrelationships an entity can participate in.

    s Beware: the positioning of the constraints is exactly the reverseof the positioning of constraints in E-R diagrams.

    s The constraint 0..* on the E2side and 0..1 on the E1 side means

    that each E2 entity can participate in at most one relationship,whereas each E1 entity can participate in many relationships; inother words, the relationship is many to one from E2 to E1.

    s Single values, such as 1 or * may be written on edges; Thesingle value 1 on an edge is treated as equivalent to 1..1, while *is equivalent to 0..*.

  • 8/14/2019 Entity Relationship Model (CommenteD)

    67/82

    Database System Concepts, 5th Ed.

    Silberschatz, Korth and SudarshanSee www.db-book.com for conditions on re-use

    End of Chapter 2End of Chapter 2

    http://www.db-book.com/http://www.db-book.com/
  • 8/14/2019 Entity Relationship Model (CommenteD)

    68/82

    E-R Diagram for Exercise 2.15E-R Diagram for Exercise 2.15

  • 8/14/2019 Entity Relationship Model (CommenteD)

    69/82

    Silberschatz, Korth and Sudarshan6.69Database System Concepts - 5th Edition, July 11, 2005

    E R Diagram for Exercise 2.15E R Diagram for Exercise 2.15

    E-R Diagram for Exercise 2.22E-R Diagram for Exercise 2.22

  • 8/14/2019 Entity Relationship Model (CommenteD)

    70/82

    Silberschatz, Korth and Sudarshan6.70Database System Concepts - 5th Edition, July 11, 2005

    E R Diagram for Exercise 2.22E R Diagram for Exercise 2.22

    E-R Diagram for Exercise 2.15E-R Diagram for Exercise 2.15

  • 8/14/2019 Entity Relationship Model (CommenteD)

    71/82

    Silberschatz, Korth and Sudarshan6.71Database System Concepts - 5th Edition, July 11, 2005

    E R Diagram for Exercise 2.15E R Diagram for Exercise 2.15

  • 8/14/2019 Entity Relationship Model (CommenteD)

    72/82

    Figure 6.8Figure 6.8

  • 8/14/2019 Entity Relationship Model (CommenteD)

    73/82

    Silberschatz, Korth and Sudarshan6.73Database System Concepts - 5th Edition, July 11, 2005

    Figure 6.8gu e 6 8

    Figure 6.15Figure 6.15

  • 8/14/2019 Entity Relationship Model (CommenteD)

    74/82

    Silberschatz, Korth and Sudarshan6.74Database System Concepts - 5th Edition, July 11, 2005

    gu e 6 5g

    Figure 6.16Figure 6.16

  • 8/14/2019 Entity Relationship Model (CommenteD)

    75/82

    Silberschatz, Korth and Sudarshan6.75Database System Concepts - 5th Edition, July 11, 2005

    gu eg

    Figure 6.26Figure 6.26

  • 8/14/2019 Entity Relationship Model (CommenteD)

    76/82

    Silberschatz, Korth and Sudarshan6.76Database System Concepts - 5th Edition, July 11, 2005

    gg

    Figure 6.27Figure 6.27

  • 8/14/2019 Entity Relationship Model (CommenteD)

    77/82

    Silberschatz, Korth and Sudarshan6.77Database System Concepts - 5th Edition, July 11, 2005

    gg

    Figure 6.28Figure 6.28

  • 8/14/2019 Entity Relationship Model (CommenteD)

    78/82

    Silberschatz, Korth and Sudarshan6.78Database System Concepts - 5th Edition, July 11, 2005

    gg

    Figure 6.29Figure 6.29

  • 8/14/2019 Entity Relationship Model (CommenteD)

    79/82

    Silberschatz, Korth and Sudarshan6.79Database System Concepts - 5th Edition, July 11, 2005

    gg

    Figure 6.30Figure 6.30

  • 8/14/2019 Entity Relationship Model (CommenteD)

    80/82

    Silberschatz, Korth and Sudarshan6.80Database System Concepts - 5th Edition, July 11, 2005

    gg

    Figure 6.31Figure 6.31

  • 8/14/2019 Entity Relationship Model (CommenteD)

    81/82

    Silberschatz, Korth and Sudarshan6.81Database System Concepts - 5th Edition, July 11, 2005

    gg

    Alternative E-R NotationsAlternative E-R Notations

  • 8/14/2019 Entity Relationship Model (CommenteD)

    82/82

    te at e otat o sFigure 6.24Figure 6.24