2 the entity-relationship model

Upload: shubham

Post on 02-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 2 the Entity-Relationship Model

    1/20

    1

    The Entity-Relationship ModelPart I.

  • 8/10/2019 2 the Entity-Relationship Model

    2/20

    2

    Database Design Stages

    Application

    Requirements

    Conceptual

    Design

    Logical Design

    Physical Design

    Conceptual Schema

    Logical Schema

    Physical Schema

  • 8/10/2019 2 the Entity-Relationship Model

    3/20

    3

    Conceptual Design

    What is Conceptual Design? Concise representation of the DB application requirements

    Why Conceptual Design ?

    It helps to understand application requirements better

    It helps to communicate our understanding of application

    It helps to come up with a gooddesign

  • 8/10/2019 2 the Entity-Relationship Model

    4/20

    4

    Conceptual Design (Contd)

    Conceptual Models ER (Entity-Relationship)Model, Our focus

    UML (Unified Modeling Language),

    ORM (Object Role Modeling), etc.

    ER Model Structures: Entitiesand Relationships

    Constraints

    An ER schema is represented using Entity-RelationshipDiagram (ERD)

  • 8/10/2019 2 the Entity-Relationship Model

    5/20

    Modeling

    A database can be modeled as: Collection of entities,

    Relationship among entities.

    An entityis an object that exists and is distinguishable fromother objects. Example: a person, company, event, bank account, store, etc.

    Entities have attributes Example: a person have names and addresses

    An entity set is a set of entities of the same type that sharethe same properties. Example: set of all persons, companies, trees, holidays

    5

  • 8/10/2019 2 the Entity-Relationship Model

    6/20

    6

    ER: Entity Sets and Attributes

    Entity set :Represent a set of objects Attribute:property of an entity, has a domain

    In ER diagram

    Entity setrectangle

    AttributeOval.

    Student

    sNamesNumber

    sAge

    Entity Set Student

    with attributes (sNumber, sName, sAge)

  • 8/10/2019 2 the Entity-Relationship Model

    7/20

    Attributes Types

    Primitive attributes: Attribute stores a single value (Number, String,Boolean, Date, )

    Composite attributes: An attribute can be divided into sub-attributes

    (each is primitive)

    Multi-values attributes: Attribute with many values

    Derived attributes: Attributes computed from others

    7

    Student

    sNamesNumber

    sAge

    These are primitive

    attributes

    DoB

  • 8/10/2019 2 the Entity-Relationship Model

    8/20

    8

    Complex Attributes

    Composite Attribute: address Multivalued Attribute: major

    major

    statestreet

    address

    city

    Derived Attribute: Age

    Age

    Studententity set

    with all its attributes

    Student

    sNamesNumber

    sAge

    major

    statestreet

    address

    city

    Age

    DoB

  • 8/10/2019 2 the Entity-Relationship Model

    9/20

    9

    Relationship Types

    Relationship:Association (connection) between entities sets

    Relationship Type:Class of relationships

    Representation: Use a diamond shape

    Student

    sNumber

    sName

    Course

    cNumber

    title

    Has

    Taken

    Relationship type HasTakento represent

    Coursestaken by Students

  • 8/10/2019 2 the Entity-Relationship Model

    10/20

    10

    Relationships with Attributes

    Student

    sNumber

    sName

    Course

    cNumber

    title

    Has

    Taken

    project

    Relationship HasTakenhas an attribute projectwhich is the

    project the Studentdid for the Course

    Student

    sNumber

    sName

    Course

    cNumber

    title

    Has

    Taken

    A relationship may have attributes

    These attributes do notbelong to any of the connected entities. But theybelong the relationship

  • 8/10/2019 2 the Entity-Relationship Model

    11/20

    11

    Example I (Simple Application)

    Suppliershave a name, and location.Productshave a name, price, and number.Consumershave a name, and location.

    Suppliers supply products on certain dates, while consumers buyproducts of certain quantity

    How would you model this application?

    a) What are the entities and attributes?b) What are the relationships?

  • 8/10/2019 2 the Entity-Relationship Model

    12/20

    Modeling of Example I

    12

    supplier

    sName

    sLoc

    consumer

    cName

    cLoc

    product

    pNumber sNamesPrice

    supplies buys

    datequantity

    This ER captures exactly what is written in text

  • 8/10/2019 2 the Entity-Relationship Model

    13/20

    13

    Example II (More Complicated)

    Suppliershave a name, and location.

    Productshave a name, and number.

    Consumers have a name, and location.

    SomeSuppliershave established contracts to supply a certain Productto a

    particular Consumerfor specially negotiated price at a given quantity.

    How would you model this application?

  • 8/10/2019 2 the Entity-Relationship Model

    14/20

    14

    Modeling of Example II

    Supplier

    sName

    sLoc

    Consumer

    cName

    cLoc

    Supply

    price

    Product

    pName pNumber

    qty

    Model the relationship Suppliersupplies Productsto Consumers

    Ternary relationship

    (three-way)

  • 8/10/2019 2 the Entity-Relationship Model

    15/20

    Binary vs. Multi-way Relationships

    15

    supplier

    sName

    sLoc

    consumer

    cName

    cLoc

    product

    pNumber sName

    supplies buys

    pricequantity

    Binary relationship

  • 8/10/2019 2 the Entity-Relationship Model

    16/20

    Recursive Relationship Type:

    Another Example An relationship type whose with the same participating entity

    type in distinct roles

    Example: the SUPERVISION relationship

    EMPLOYEE participates twice in two distinct roles:

    supervisor (or boss) role

    supervisee (or subordinate) role

    Each relationship instance relates two distinct EMPLOYEE

    entities:

    One employee in supervisorrole

    One employee in superviseerole

  • 8/10/2019 2 the Entity-Relationship Model

    17/20

    A RECURSIVE RELATIONSHIP

    SUPERVISION

    e1

    e2

    e3

    e4

    e5

    e6

    e7

    EMPLOYEE

    r1

    r2

    r3

    r4

    r5

    r6

    SUPERVISION

    2

    1

    12

    2

    1

    1

    12

    1

    2

    2

  • 8/10/2019 2 the Entity-Relationship Model

    18/20

    19

    ER Model so far

    Entities and entity sets

    Relationships

    Binary, ternary, multi-way

    Attributes

    For entity sets and relationship types

    Simple, composite, multi-valued, derived

  • 8/10/2019 2 the Entity-Relationship Model

    19/20

    What about an Exercise

    Assume you are building a database for a

    Bank

    What are the entity sets, attributes, and

    relationships??

    20

  • 8/10/2019 2 the Entity-Relationship Model

    20/20

    E-R Diagram for a Banking Enterprise