Database Systems-Lec3

Embed Size (px)

Citation preview

  • 8/14/2019 Database Systems-Lec3

    1/56

    Chapter 5Entity Relationship (E-R)Modeling

  • 8/14/2019 Database Systems-Lec3

    2/56

    Basic Modeling Concepts Database design is both art and science.

    A data model is the relatively simplerepresentation, usually graphic, of

    complex real-world data structures. Itrepresents data structures and theircharacteristics, relations, constraints, andtransformations.

    The database designer usually employsdata models as communications tools tofacilitate the interaction among thedesigner, the applications programmer,

    and the end user.

  • 8/14/2019 Database Systems-Lec3

    3/56

    Data Models: Degrees of Data

    Abstraction

    Figure 2.10 page 57

  • 8/14/2019 Database Systems-Lec3

    4/56

    The conceptual model represents a global viewof the data. It is an enterprise-widerepresentation of data as viewed by high-levelmanagers.

    Entity-Relationship (E-R) model is the most

    widely used conceptual model.

    The conceptual model forms the basis for theconceptual schema.

    The conceptual schema is the visualrepresentation of the conceptual model.

    The conceptual model is independent of bothsoftware (software independence) andhardware (hardware independence).

    The Conceptual Model

  • 8/14/2019 Database Systems-Lec3

    5/56

    Tiny College Entities

    Figure 2.11 Page 58

  • 8/14/2019 Database Systems-Lec3

    6/56

    A Conceptual Schema for Tiny College

    Figure 2.12 Page 59

  • 8/14/2019 Database Systems-Lec3

    7/56

    The Internal Model

    The internal model adapts theconceptual model to a specific DBMS.

    The internal model is software-dependent.

    Development of the internal model is

    especially important to hierarchical andnetwork database models.

  • 8/14/2019 Database Systems-Lec3

    8/56

    Figure 2.13 Page 61

  • 8/14/2019 Database Systems-Lec3

    9/56

    Figure 2.13 Page 61

  • 8/14/2019 Database Systems-Lec3

    10/56

    The external model is the end usersview of the data environment.

    Each external model is thenrepresented by its own externalschema.

    CREATE VIEW CLASS_VIEW ASSELECT (CLASS_ID, CLASS_NAME,PROF_NAME, CLASS_TIME, ROOM_ID)FROM CLASS, PROFESSOR, ROOMWHERE CLASS.PROF_ID =

    PROFESSOR.PROF_ID AND CLASS.ROOM_ID= ROOM.ROOM_ID;

    The ExternalModel/Schema

  • 8/14/2019 Database Systems-Lec3

    11/56

    External

    Model

    Extern

    alModel

    Figure 2.14 Page 63

  • 8/14/2019 Database Systems-Lec3

    12/56

    Advantages of Using External Schemas

    It makes application programdevelopment much simpler.

    It facilitates the designers task bymaking it easier to identify specificdata required to support each businessunits operations.

    It makes the designers job easier byproviding feedback about theconceptual models adequacy.

    It helps to ensure security constraints

    The ExternalModel/Schema

  • 8/14/2019 Database Systems-Lec3

    13/56

    The physical model operates at thelowest level of abstraction, describing theway data is saved on storage media suchas disks or tapes.

    It requires the definition of both thephysical storage devices and the accessmethods required to reach the datawithin those storage devices.

    The physical model is both software andhardware-dependent.

    It requires detailed knowledge of

    hardware and software used to

    The Physical Model

  • 8/14/2019 Database Systems-Lec3

    14/56

    Entity Relationship (E-R)

    Model

    E-R model is commonly used to:

    Translate different views of dataamong managers, users, andprogrammers to fit into acommon framework.

    Define data processing andconstraint requirements to helpus meet the different views.

    Help implement the database.

  • 8/14/2019 Database Systems-Lec3

    15/56

    E-R Model Components

    Entities

    In E-R models an entity refers to the entity set.

    An entity is represented by a rectangle

    containing the entitys name.

    Attributes

    Attributes are represented by ovals and areconnected to the entity with a line.

    Each oval contains the name of the attribute it

    represents. Attributes have a domain -- the attributes set of

    possible values.

    Attributes may share a domain.

    Primary keys are underlined.

    Relationships

    Entity Relationship (E-R)

    Model

  • 8/14/2019 Database Systems-Lec3

    16/56

    Attributes of the STUDENT Entity

    Figure 4.1 Page 125

  • 8/14/2019 Database Systems-Lec3

    17/56

    Basic E-R Model Entity Presentation

    Figure 4.3 Page 127

  • 8/14/2019 Database Systems-Lec3

    18/56

    The CLASS Table (Entity)

    Components and Contents

    Figure 4.2 Page 126

    Cl f

  • 8/14/2019 Database Systems-Lec3

    19/56

    A simple attribute cannot be subdivided.

    Examples: Age, Sex, and Maritalstatus

    A composite attribute can be furthersubdivided to yield additional attributes.

    Examples:

    ADDRESS - Street, City, State, Zip

    PHONE NUMBER - Area code,Exchange number

    Classes ofAttributes

    Classes of

  • 8/14/2019 Database Systems-Lec3

    20/56

    A single-valued attribute can have only asingle value.

    Examples:

    A person can have only one socialsecurity number.

    A manufactured part can have only oneserial number.

    Multivalued attributes can have manyvalues.

    Examples:

    A person may have several collegedegrees.

    A household may have several phones

    with different numbers

    Classes ofAttributes

  • 8/14/2019 Database Systems-Lec3

    21/56

    Splitting the Multivalued Attributes

    into New Attributes

    Figure 4.4 Page 128

  • 8/14/2019 Database Systems-Lec3

    22/56

    A New Entity Set Composed of

    Multivalued Attributes Components

    Figure 4.5 Page 129

  • 8/14/2019 Database Systems-Lec3

    23/56

    A derived attribute is not physically storedwithin the database; instead, it is derived byusing an algorithm.

    Example: AGE can be derived from the data

    of birth and the current date.

    Emp_Age = Current Date - Emp_DOB

    Derived Attributes

    Figure 4.6 Page 130

  • 8/14/2019 Database Systems-Lec3

    24/56

    A relationship is an association betweenentities.

    Relationships are represented by diamond-shaped symbols.

    Relationship

    Figure 4.7 Page 132

  • 8/14/2019 Database Systems-Lec3

    25/56

    A relationships degree indicates thenumber of associated entities orparticipants.

    A unary relationship exists when anassociation is maintained within a singleentity.

    A binary relationship exists when twoentities are associated.

    A ternary relationship exists when threeentities are associated.

    Relationship Degree

  • 8/14/2019 Database Systems-Lec3

    26/56

    Relationship Degree

    Figure 4.16 Page 143

  • 8/14/2019 Database Systems-Lec3

    27/56

    The Implementation

    of a TernaryRelationship

    Figure 4.17 Page 144

  • 8/14/2019 Database Systems-Lec3

    28/56

    Connectivity

    The term connectivity is used to describethe relationship classification (e.g., one-to-one, one-to-many, and many-to-many).

    Connectivity

    Figure 4.7 Page 132

  • 8/14/2019 Database Systems-Lec3

    29/56

    Cardinality

    Cardinality expresses the specific numberof entity occurrences associated with oneoccurrence of the related entity.

    Cardinality

    Figure 4.7 Page 132

  • 8/14/2019 Database Systems-Lec3

    30/56

    If an entitys existence

    depends on the existenceof one or more otherentities, it is said to be

    existence-dependent.

    ExistenceDependency

  • 8/14/2019 Database Systems-Lec3

    31/56

    Weak Relationship

    Class will not exist if course does not exist.

    Class depends on Course

    Figure 4.9 Page 134

  • 8/14/2019 Database Systems-Lec3

    32/56

  • 8/14/2019 Database Systems-Lec3

    33/56

    CLASS is Optional to COURSE

    Figure 4.12 Page 138

  • 8/14/2019 Database Systems-Lec3

    34/56

    COURSE and CLASS in a Mandatory

    Relationship

    Figure 4.13 Page 139

  • 8/14/2019 Database Systems-Lec3

    35/56

    Weak Entities A weak entity is an entity that

    Is existence-dependent and

    Has a primary key that is partially ortotally derived from the parent entityin the relationship.

    The existence of a weak entity is

    indicated by a double rectangle. Theweak entity inherits all or part of itsprimary key from its strongcounterpart.

    Weak Entities

  • 8/14/2019 Database Systems-Lec3

    36/56

    A Weak Entity in an ERD

    Figure 4.14 Page 140

  • 8/14/2019 Database Systems-Lec3

    37/56

    Weak Relationship Between

    DEPENDENT and EMPLOYEE

    Figure 4.15 Page 141

  • 8/14/2019 Database Systems-Lec3

    38/56

    Recursive Entities

    A recursive entity is one in which arelationship can exist betweenoccurrences of the same entity set.

    A recursive entity is found within aunary relationship.

    Recursive Entities

    Figure 4.18 Page 145

  • 8/14/2019 Database Systems-Lec3

    39/56

    1. James Ramirez is married to Louise Ramirez, who ismarried to

    James Ramirez

    2. Anne Jones is married to Anton shapiro, who is married to

    AnneJones

    Recursive Entities

    Figure 4.19 Page 145

  • 8/14/2019 Database Systems-Lec3

    40/56

    A rotor assembly is composed of four 2.5cm washers,two cotter pins, one 2.5 cm steel shank, four 10.25cmrotor blades, and two 2.5 cm hex nuts

    Recursive Entities

    Figure 4.20 Page 146

  • 8/14/2019 Database Systems-Lec3

    41/56

    The Implementation of the M:N Recursive

    PART Contains PART Relationship

    Figure 4.21 Page 146

  • 8/14/2019 Database Systems-Lec3

    42/56

    Implementation of the M:N COURSE

    Requires COURSE RecursiveRelationship

    Figure 4.22 Page 147

  • 8/14/2019 Database Systems-Lec3

    43/56

    Implementation of the 1:M EMPLOYEE

    Manages EMPLOYEE RecursiveRelationship

    Figure 4.23 Page 147

  • 8/14/2019 Database Systems-Lec3

    44/56

    A composite entity is composed of theprimary keys of each of the entities to beconnected.

    The composite entity serves as a bridgebetween the related entities.

    The composite entity may containadditional attributes.

    Composite Entities

  • 8/14/2019 Database Systems-Lec3

    45/56

    The M:N Relationship Between

    STUDENT and CLASS

    Figure 4.25 Page 149

  • 8/14/2019 Database Systems-Lec3

    46/56

    A Composite Entity in the ERD

    Figure 4.26 Page 149

  • 8/14/2019 Database Systems-Lec3

    47/56

    Converting the M:N Relationship

    Into Two 1:M Relationships

    Figure 4.24 Page 148

  • 8/14/2019 Database Systems-Lec3

    48/56

    Entity Supertypes and Subtypes

    Figure 4.27 Page 150

  • 8/14/2019 Database Systems-Lec3

    49/56

    The generalization hierarchy depicts the

    parent-child relationship.

    The supertype contains the sharedattributes, while the subtype contains

    the unique attributes. A subtype entity inherits its attributes

    and its relationships from the supertypeentity.

    Entity Supertypes and Subtypes

  • 8/14/2019 Database Systems-Lec3

    50/56

    A Generalization Hierarchy

    Figure 4.28 Page 151

  • 8/14/2019 Database Systems-Lec3

    51/56

    Entity Supertypes and Subtypes

    The supertype entity set is usuallyrelated to several unique and

    disjointed (nonoverlapping) subtypeentity sets.

    The supertype and its subtype(s)maintain a 1:1 relationship.

    Entity Supertypes and Subtypes

  • 8/14/2019 Database Systems-Lec3

    52/56

    The EMPLOYEE/PILOT

    Supertype/Subtype Relationship

    Figure 4.29 Page 152

  • 8/14/2019 Database Systems-Lec3

    53/56

    Entity Supertypes and Subtypes

    The generalization hierarchy depictsthe parent-child relationship. (Figure4.34)

    The supertype contains the shared

    attributes, while the subtype containsthe unique attributes.

    The supertype entity set is usuallyrelated to several unique and

    disjointed (nonoverlapping) subtype

    Entity Supertypes and Subtypes

  • 8/14/2019 Database Systems-Lec3

    54/56

    A Generalization Hierarchy

    With Overlapping Subtypes

    Figure 4.30 Page 153

  • 8/14/2019 Database Systems-Lec3

    55/56

  • 8/14/2019 Database Systems-Lec3

    56/56

    References

    ROB, P. AND CORONEL, C., 2004, Database

    Systems. 6th Ed., Thomson Course Technology