4.Entity Relationship Model2

download 4.Entity Relationship Model2

of 28

Transcript of 4.Entity Relationship Model2

  • 8/8/2019 4.Entity Relationship Model2

    1/28

    CST203-2 Database Management Systems

    Lecture 4

  • 8/8/2019 4.Entity Relationship Model2

    2/28

    Student entity

    NID FName LName RegNo ExamId Birthdate

  • 8/8/2019 4.Entity Relationship Model2

    3/28

    Keys

    y AKey is a single attribute or combination of two or

    more attributes of an entity set that is used to identifyone or more instances of the set

  • 8/8/2019 4.Entity Relationship Model2

    4/28

    Student entity

    NID FName LName RegNo ExamId Birthdate

  • 8/8/2019 4.Entity Relationship Model2

    5/28

    Super Key

    y Asuper key of an entity set is a set of one or more

    attributes whose values uniquely determine eachentity.

    y Asuperkey is any set of attributes (K) such that no two

    tuples of a relation can have the same values for K, i.e:t1(K) != t2(K) for every possible pair of distinct tuples,t1,t2.

  • 8/8/2019 4.Entity Relationship Model2

    6/28

    Student entity

    NID FName LName RegNo ExamId Birthdate

  • 8/8/2019 4.Entity Relationship Model2

    7/28

    Candidate Key

    y Acandidate key is a superkey such that no proper

    subset of K is also a superkey.y Customer-idis candidate key ofcustomer

    y account-numberis candidate key ofaccount

  • 8/8/2019 4.Entity Relationship Model2

    8/28

    Student entity

    NID FName LName RegNo ExamId Birthdate

  • 8/8/2019 4.Entity Relationship Model2

    9/28

    Primary key

    y Although several candidate keys may exist, one of the

    candidate keys is selected to be theprimary key.

    y Primary key does not allow duplicate values(repeating)and null values

  • 8/8/2019 4.Entity Relationship Model2

    10/28

    Student entity

    NID FName LName RegNo ExamId Birthdate

  • 8/8/2019 4.Entity Relationship Model2

    11/28

    Unique key

    y It wont allow duplicate values including NULL...

    y Means that it will allow any thing only one time....including null...

  • 8/8/2019 4.Entity Relationship Model2

    12/28

    Strong entity types

    y Regular entity types which have a primary key

    attributes

  • 8/8/2019 4.Entity Relationship Model2

    13/28

    Weak Entity Typesy An entity type that does not have a primary key

    y The existence of a weak entity type depends on the existence of a

    identifying or owner entity typey it must relate to the identifying entity set via a total, one-to-many

    relationship set from the identifying to the weak entity sety Identifying relationship depicted using a double diamondy Total participation constraint

    y The discriminator(or partialkey) of a weak entity set is the setof attributes that distinguishes among all the entities of a weakentity set.

    y Weak entity as an attribute

  • 8/8/2019 4.Entity Relationship Model2

    14/28

    y We depict a weak entity set by double rectangles.

    y We underline the discriminator of a weak entity set with a dashed line.

    y payment-number discriminator of thepayment entity set

    yPrimary key forpayment (loan-number, payment-number)

  • 8/8/2019 4.Entity Relationship Model2

    15/28

    y In a university, a course is a strong entity and a course-offering can be modeled as a weak entity

    y The discriminator ofcourse-offeringwould be semester(including year) and section-number(if there is more thanone section)

    yIf we model course-offering as a strong entity we wouldmodel course-numberas an attribute.

    Then the relationship with coursewould be implicit in thecourse-numberattribute

  • 8/8/2019 4.Entity Relationship Model2

    16/28

    Design of ER diagramInitial design is created and then iteratively refined until the most suitable design

    is reached

    1. Concept may be first modeled as an attribute and then refined in to

    relationship(binary)

    2. An attribute that exists in several entity types may be elevated or promotedto an independent entity type

    e.g.: student, instructor, course has the common attributedepartment number

    3. Inverse of 2nd one : if an entity type exists with a single attribute and isrelated to only one entity .

    4. Refine using specialization, generalization and relationships of higherdegree

  • 8/8/2019 4.Entity Relationship Model2

    17/28

    Specializationy Top-down design process

    y we designate subgroupings within an entity set that are distinctive from other

    entities in the set.

    y Specific attributes

    y Specific relationships

    yDepicted by a triangle component labeled ISA(E.g. customeris aperson).

    y Attribute inheritance a lower-level entity set inherits all the attributes andrelationship participation of the higher-level entity set to which it is linked

  • 8/8/2019 4.Entity Relationship Model2

    18/28

  • 8/8/2019 4.Entity Relationship Model2

    19/28

  • 8/8/2019 4.Entity Relationship Model2

    20/28

  • 8/8/2019 4.Entity Relationship Model2

    21/28

  • 8/8/2019 4.Entity Relationship Model2

    22/28

    Insertion and deletion rules for

    specialization and generalizationy Deleting from superclass

    y Inserting in a superclassy Predicate defined specialization

    y Total specialization

  • 8/8/2019 4.Entity Relationship Model2

    23/28

    Aggregationy Aclass type really represents a collection of individual

    components

  • 8/8/2019 4.Entity Relationship Model2

    24/28

    y The system is an aggregation of components

    y It denotes an "is part of" relationship

  • 8/8/2019 4.Entity Relationship Model2

    25/28

    E-R Diagram for a Banking Enterprise

  • 8/8/2019 4.Entity Relationship Model2

    26/28

  • 8/8/2019 4.Entity Relationship Model2

    27/28

  • 8/8/2019 4.Entity Relationship Model2

    28/28

    Alternative E-R Notations