Top Banner

of 30

3.Entity Relationship Model

Apr 10, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/8/2019 3.Entity Relationship Model

    1/30

    CST203-2 Database Management Systems

    Lecture 3

  • 8/8/2019 3.Entity Relationship Model

    2/30

    y Describes data as entities, relationships and attributes

  • 8/8/2019 3.Entity Relationship Model

    3/30

    Database Design Processy Requirements collection process

    y Data and functional requirements

    y

    Conceptual designy Descriptions on entity types, relationships and constraints

    y Choose a DBMS

    y Data model mapping

    y Physical database design

    y Database system implementation

  • 8/8/2019 3.Entity Relationship Model

    4/30

    Entity Setsy Adatabase can be modeled as:

    y a collection of entities,y relationship among entities.

    y An entity is an object that exists and is distinguishable from other objects.y Example: specific person, company, event, plant

    y Entities have attributesy Example: people have names and addresses

    y An entity type is a collection of entries that have the same attributes

    y An entity set is a collection of entities of a particular entity type in the databaseat any point in time

  • 8/8/2019 3.Entity Relationship Model

    5/30

    Entity Sets

    customerand loan

  • 8/8/2019 3.Entity Relationship Model

    6/30

    Attributesy Particular properties of an entity that describe it

    Example:customer = (customer-id, customer-name,customer-street, customer-city)

    loan = (loan-number, amount)

    y Domain the set of permitted values for each attribute (value set)

    y Attribute types:y Simple and composite attributes.y Single-valuedand multi-valuedattributes

    y E.g. multivaluedattribute:phone-numbersy Stored and derivedattributes

    y Can be computed from other attributesy E.g. age, given date of birth

    y Complex attributesy Key attributes

  • 8/8/2019 3.Entity Relationship Model

    7/30

    y An attributeAof entity type E whose value set is Vy A: E P(V)

    y The value of attributeAof entity ey A(e)

    y For composite attributeA, the value set Vy V = P(V1) * P(V2) * * P(Vn)

  • 8/8/2019 3.Entity Relationship Model

    8/30

    Composite Attributes

  • 8/8/2019 3.Entity Relationship Model

    9/30

    Uniqueness constrainty Key attributes

    y Composite key attributesy Composite key must be minimal

    y Prohibits any two entities from having the same value

    for the key attribute at the same time

  • 8/8/2019 3.Entity Relationship Model

    10/30

    y DEPARTMENTy Name, Number, {Locations}, Manager, ManagerStartDate

    y PROJECTy Name, Number, Location, ControllingDepartment

    y EMPLOYEEy Name(Fname, Initial, LName), ENO, Sex,Address, Salary, DOB,

    Department, Supervisor, {WorksOn(Project, Hours)}

    y DEPENDENTy Employee, DependentName, Sex, DOB, Relationship

  • 8/8/2019 3.Entity Relationship Model

    11/30

    Relationship Setsy Arelationship is an association among several entities

    Example:Hayes depositor A-102

    customerentity relationship set account entity

    y A relationship type is a set ofassociations

    y Arelationship set is a set ofassociations among entities from these entity typesy mathematical relation among n u 2 entities, each taken from entity sets

    {(e1, e2, en) | e1 E1, e2 E2, , en En}

    where (e1, e2, , en) is a relationshipe1, e2, , en are entity instancesE1,E2, E3, .. are entity types

    y Example:(Hayes,A-102) depositor

  • 8/8/2019 3.Entity Relationship Model

    12/30

    Relationship Set borrower

  • 8/8/2019 3.Entity Relationship Model

    13/30

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

    y For instance, the depositorrelationship set between entity setscustomerand account may have the attribute access-date

  • 8/8/2019 3.Entity Relationship Model

    14/30

    Degree of a Relationship Sety Refers to number of entity types that participate in a relationship type

    y Relationship types that involve two entity types are binary (or degree two)

    y Generally, most relationship sets in a database system are binary.

    y Relationship sets may involve more than two entity sets.

    y E.g. Suppose employees of a bank may have jobs (responsibilities) at multiple

    branches, with different jobs at different branches. Then there is a ternaryrelationship set between entity sets employee, job and branch

    y Relationships as attributes

  • 8/8/2019 3.Entity Relationship Model

    15/30

    E-R Diagram with a Ternary

    Relationship

  • 8/8/2019 3.Entity Relationship Model

    16/30

    Converting Non-Binary

    Relationships to Binary Formy In general, any non-binary relationship can be represented using binary

    relationships by creating an artificial entity set.y ReplaceRbetween entity setsA, B and C by an entity setE, and three relationship sets:

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

    3. RC, relating Eand Cy Create a special identifying attribute for E

    y Add any attributes ofRto E

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

    1. a new entityei in the entity set E 2. add (ei, ai ) to RA3. add (ei, bi ) to RB 4. add (ei, ci ) to RC

  • 8/8/2019 3.Entity Relationship Model

    17/30

    Mapping Cardinalitiesy Express the number of entities to which another entity can be associated via a

    relationship set.

    y Most useful in describing binary relationship sets.

    y For a binary relationship set the mapping cardinality must be one of the following types:y One to oney One to manyy Many to oney Many to many

    y Cardinality ratioy Maximum number of relationship instances that an entity can participate in

    1:11:NN:1N:N

  • 8/8/2019 3.Entity Relationship Model

    18/30

    Some elements inAand B may not be mapped to any elements in the other set

  • 8/8/2019 3.Entity Relationship Model

    19/30

  • 8/8/2019 3.Entity Relationship Model

    20/30

  • 8/8/2019 3.Entity Relationship Model

    21/30

    Mapping Cardinalities affect ER

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

    attribute, if each account can have only one customer

    y I.e., the relationship from account to customer is many to one, orequivalently, customer to account is one to many

  • 8/8/2019 3.Entity Relationship Model

    22/30

    E-R Diagrams

    y Rectangles represent entity sets.

    yDiamonds represent relationship sets.

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

    y Ellipses represent attributes

    y Double ellipses represent multivalued attributes.

    y Dashed ellipses denote derived attributes.

    y Underline indicates primary key attributes (will study later)

  • 8/8/2019 3.Entity Relationship Model

    23/30

    E-R Diagram With Composite,

    Multivalued, and Derived Attributes

  • 8/8/2019 3.Entity Relationship Model

    24/30

    Relationship Sets with Attributes

  • 8/8/2019 3.Entity Relationship Model

    25/30

    Rolesy Entity sets of a relationship need not be distinct

    y The labels manager and worker are called roles; they specify how employeeentities interact via the works-for relationship set.

    y Roles are indicated in E-Rdiagrams by labeling the lines that connectdiamonds to rectangles.

    y Role labels are optional, and are used to clarify semantics of the relationship

  • 8/8/2019 3.Entity Relationship Model

    26/30

    Cardinality Constraintsy We express cardinality constraints by drawing either a directed line (p),

    signifying one, or an undirected line (), signifying many, between therelationship set and the entity set.

    y E.g.: One-to-one relationship:y Acustomer is associated with at most one loan via the relationship borrowery Aloan is associated with at most one customer via borrower

  • 8/8/2019 3.Entity Relationship Model

    27/30

    One-To-Many Relationshipy In the one-to-many relationship a loan is associated with at most

    one customer via borrower, a customer is associated with several(including 0) loans via borrower

  • 8/8/2019 3.Entity Relationship Model

    28/30

    Many-To-One Relationshipsy In a many-to-one relationship a loan is associated with several

    (including 0) customers via borrower, a customer is associated with atmost one loan via borrower

  • 8/8/2019 3.Entity Relationship Model

    29/30

    Many-To-Many Relationship

    y Acustomer is associated with several (possibly 0) loans viaborrower

    y Aloan is associated with several (possibly 0) customers viaborrower

  • 8/8/2019 3.Entity Relationship Model

    30/30

    Participation of an Entity Set in

    a Relationship Sety Total participation (indicated by double line): every entity in the entity set

    participates in at least one relationship in the relationship set

    y E.g. participation ofloan in borroweris totaly every loan must have a customer associated to it via borrower

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

    y E.g. participation ofcustomerin borrower is partial