BD Ch#2

Embed Size (px)

Citation preview

  • 7/31/2019 BD Ch#2

    1/35

    Chapter 2

    Entity Relationship Model

    (ER Model)Muddassar AliInternational University of Technology Twintech (IUTT) Yemen

    [email protected]

  • 7/31/2019 BD Ch#2

    2/35

    E-R Model Concepts The ER model describes data as:

    Entities

    AttributesRelationships between entities

    The overall logical structure of a database can beexpressed graphically by ER diagram.

    Muddassar Ali 2

  • 7/31/2019 BD Ch#2

    3/35

    Muddassar Ali 3

    Relationshipdegreesspecifynumber of

    entity typesinvolved

    Entitysymbols

    A special entitythat is also arelationship

    Relationship symbols

    Relationshipcardinalitiesspecify howmany of eachentity type is

    allowed

    Attributesymbols

  • 7/31/2019 BD Ch#2

    4/35

    Entities An entity is an object that exists and isdistinguishable from other objects.

    Example: specific person, company, event, plant etcEntities have attributes

    An entity set is a set of entities of the same type that

    share the same properties.Example: set of all persons, companies, trees etc.

    Muddassar Ali 4

  • 7/31/2019 BD Ch#2

    5/35

    AttributesAttribute - property or characteristic of an entity type

    Example: COURSE entity has attributes

    Course code Course Title Course Description Number of Credits

    Classifications of attributes:Required versus Optional AttributesSimple versus Composite AttributeSingle-Valued versus Multi-valued AttributeStored versus Derived Attributes

    Muddassar Ali 5

  • 7/31/2019 BD Ch#2

    6/35

    Required versus Optional AttributesRequired attribute is that which is must for an entityit must not be null.

    Optional is not necessary for an entity it may benull.

    Muddassar Ali 6

  • 7/31/2019 BD Ch#2

    7/35

    Simple versus Composite AttributeSimple attribute is atomic and cannot be further divided

    They describe simple features of an entityExample:

    Title for the COURSE entity type Age for EMPLOYEE entity type

    Composite attributes Can be divided into smaller subpartsExample:

    Address may consists of StreetAddress, City, State,ZipCode, Country

    Muddassar Ali 7

  • 7/31/2019 BD Ch#2

    8/35

    Muddassar Ali 8

    A composite attribute

  • 7/31/2019 BD Ch#2

    9/35

    Single-Valued versus Multi-valued AttributeSingle Valued attributes have only one value for each entityof an entity setEach attribute Age and/or Sex has single value for each

    EMPLOYEE entityExample: Single-valued: Gender = MMulti-valued attributes

    Have a set of values for a particular entityExample: Phone attribute may be multivalued when personhas several phones (home, office, mobile)

    Muddassar Ali 9

  • 7/31/2019 BD Ch#2

    10/35

    Stored versus Derived Attributes

    Derived Attributes are functionally related toexisting attribute(s) that are stored and can be

    calculated from that other attributes values Example: Age of an EMPLOYEE can be calculated

    from his/her Birth date

    Muddassar Ali 10

  • 7/31/2019 BD Ch#2

    11/35

    Key Attributes

    Key attribute is one or more attributes that uniquelyidentifies each entity of the entity set

    Value of key attribute Identifies each entity uniquely Must be distinct for each entity in the entity set Unique for every extension of the entity type

    A key attribute has its name underlined inside theoval

    Muddassar Ali 11

  • 7/31/2019 BD Ch#2

    12/35

    Muddassar Ali 12

    Simple key attribute

    The key is underlined

  • 7/31/2019 BD Ch#2

    13/35

    Composite key attribute

    Muddassar Ali 13

    The key is composedof two subparts

  • 7/31/2019 BD Ch#2

    14/35

    Muddassar Ali 14

    Entity with a multivalued attribute (Skill) and derived

    attribute (Years_Employed)

    Derivedfrom date employed and current date

    Primary Key

    Multivalued: an employee can havemore than one skill

  • 7/31/2019 BD Ch#2

    15/35

    Relationships

    Muddassar Ali 15

    A Relationship Type is an association among two ormore entity typesName of relationship must be Verb phraseRelationships can have attributes

    These describe features pertaining to the associationbetween the entities in the relationship

    Examples Employee Manages Departments Student Studies Course

  • 7/31/2019 BD Ch#2

    16/35

    Degree of Relationships

    Degree of a relationship is the number of entity types that participate in it

    Unary Relationship : 1 entity involvedBinary Relationship : 2 entities involvedTernary Relationship : 3 entities involvedN-ary Relationship : n-entities involved

    Muddassar Ali 16

  • 7/31/2019 BD Ch#2

    17/35

    Muddassar Ali 17

    Degree of relationships

    One entity

    related toanother of the sameentity type

    Entities of two different

    types relatedto each other Entities of threedifferent typesrelated to eachother

  • 7/31/2019 BD Ch#2

    18/35

    Cardinality of RelationshipsOne-to-One

    Each entity in the relationship will have exactly one related entityOne-to-Many

    An entity on one side of the relationship can have many relatedentities, but an entity on the other side will have a maximum of onerelated entity

    Many-to-ManyEntities on both sides of the relationship can have many related entitieson the other side

    Muddassar Ali 18

  • 7/31/2019 BD Ch#2

    19/35

    Cardinality Constraints

    Cardinality Constraints - the number of instances of one entity that can or must be associated with eachinstance of another entityMinimum Cardinality

    If zero, then optionalIf one or more, then mandatory

    Maximum CardinalityThe maximum number

    Muddassar Ali 19

  • 7/31/2019 BD Ch#2

    20/35

    Muddassar Ali 20

  • 7/31/2019 BD Ch#2

    21/35

    Muddassar Ali 21

  • 7/31/2019 BD Ch#2

    22/35

    Muddassar Ali 22

    Note: a relationship can have attributes of its own

  • 7/31/2019 BD Ch#2

    23/35

    Muddassar Ali 23

    Basic relationship with only maximum cardinalities

    Mandatory minimum cardinalities

  • 7/31/2019 BD Ch#2

    24/35

    Muddassar Ali 24

    Optional cardinalities with unary degree, one-to-one relationship

  • 7/31/2019 BD Ch#2

    25/35

    Muddassar Ali 25

  • 7/31/2019 BD Ch#2

    26/35

    Muddassar Ali 26

    Entities can be related to one another in more than one way

  • 7/31/2019 BD Ch#2

    27/35

    Muddassar Ali 27

    Here max cardinality

    constraint is 4

  • 7/31/2019 BD Ch#2

    28/35

    Strong vs. Weak Entities, and IdentifyingRelationships

    Strong entitiesexist independently of other types of entitieshas its own unique identifierrepresented with single-line rectangle

    Weak entitydependent on a strong entitycannot exist on its own does not have a unique identifierrepresented with double-line rectangle

    Identifying relationshiplinks strong entities to weak entitiesrepresented with double line diamond

    Muddassar Ali 28

  • 7/31/2019 BD Ch#2

    29/35

    Muddassar Ali 29

    Strong entity Weak entityIdentifyingrelationship

  • 7/31/2019 BD Ch#2

    30/35

    Associative EntitiesIts an entity it has attributesAND its a relationship it links entities togetherWhen should a relationship with attributes instead be anassociative entity ?

    All relationships for the associative entity should be many.The associative entity could have meaning independent of the otherentities and preferably has a unique identifier.It should also have other attributes.The associative entity may participate in other relationshipsindependent of the entities related in the associated relationship.

    Ternary relationships should be converted to associative entities

    Muddassar Ali 30

  • 7/31/2019 BD Ch#2

    31/35

    Muddassar Ali 31

    An associative entity (CERTIFICATE)

    Associative entity involves a rectangle with a diamond inside.Note that the many-to-many cardinality symbols face towardthe associative entity and not toward the other entities

    Sample E R Diagram

  • 7/31/2019 BD Ch#2

    32/35

    Muddassar Ali 32

    Sample E-R Diagram

  • 7/31/2019 BD Ch#2

    33/35

    Explanation of E-R diagram1) Customer Submits zero or many Orders but Order must be submitted by

    one customer.2) Order Request one or many Products But Product can be Requested by

    zero or many Orders.3) Item is Used_In one or many Products And Product Used one or many

    Items.4) Supplier supplied zero or many Items but item may be supplied by one or

    many suppliers.

    5) An item is included by zero or many shipments and shipment includesone or many items.

    6) one supplier sends zero or many shipments but shipment is send byexactly one supplier.

    Muddassar Ali 33

  • 7/31/2019 BD Ch#2

    34/35

  • 7/31/2019 BD Ch#2

    35/35

    Muddassar Ali

    THE END

    Any Questions???