Lt5 ERconstraints EER

Embed Size (px)

Citation preview

  • 7/29/2019 Lt5 ERconstraints EER

    1/25

  • 7/29/2019 Lt5 ERconstraints EER

    2/25

  • 7/29/2019 Lt5 ERconstraints EER

    3/25

    Outline

    Symbols used in ER Diagram Cardinality Of a relationship

    ER Constraints

    Keys. Single Value constraints.

    Foreign-key, or referential-

    integrity.Domain constraints.

    General constraints. EER concepts

  • 7/29/2019 Lt5 ERconstraints EER

    4/25

    4

    Single-value constraints

    Single-value constraintsThe value in a certain context be unique for anattribute. Keys are single-value constraints. AlsoSingle-value constraints can seen in many-onerelationships.

    Ex: 1. In students entity set, st_id is a singlevalue constraint.

    2. In courses entity set course_no is asingle value constraint.

    3. In the employees and depts entity sets, the

    relationship heads is many-one. Here foreach entry

    in employees, there will be atmost oneassociated

    entity(instance) in depts.

  • 7/29/2019 Lt5 ERconstraints EER

    5/25

    5

    Referential integrity constraints

    Weak entity: A weak entitycan beidentified uniquely only by considering theprimary key of another (owner) entity. i.e.,a weak entity can not be identified on its

    own. Owner entity set and weak entity set must

    participate in a one-to-many relationshipset (one owner, many weak entities).

    Weak entity setmust have totalparticipation in this identifying relationshipset.

  • 7/29/2019 Lt5 ERconstraints EER

    6/25

    6

    Referential integrityconstraints Example

    There must be referential integrityconstraint from weak entity set to thesupporting entity sets.

    employee dependenthas

    Emp-id

    Emp-name Dep-name

    gender

    relationship

    Birth-date

  • 7/29/2019 Lt5 ERconstraints EER

    7/25

    7

    Referential Integrity Contd..

    An integrity constraint specifying thatthe value of an attribute in one relationdepends on the value of a primary key

    in the same or another relation. i.e., ina 1:m relationship, a value in thematching column on the many side

    must correspond to a value in theprimary key for some row in therelation on the one side or be NULL.

  • 7/29/2019 Lt5 ERconstraints EER

    8/25

    8

    Domain constraint

    Constraint specifying set of values orrange of values that an attributevalue should lie.

    Ex: 1. gender should be either M orF

    2. course_no should start with

    AAOC, BITS, CS, IS..

    3. room_no should lie between 1

    to 300

  • 7/29/2019 Lt5 ERconstraints EER

    9/25

    9

    General constraints (assertions)

    Constraints/arbitrary assertions thatare specified in the database.

    Ex: 1. no_of_courses taken by astudent

    in a semester.

    2. no_of_sections for a course.

  • 7/29/2019 Lt5 ERconstraints EER

    10/25The ER conceptual schema diagram for the

  • 7/29/2019 Lt5 ERconstraints EER

    11/25

    The ER conceptual schema diagram for the COMPANY database

    (0,1) (1,1) (0,N)

    (1,1)

    (1,N)

    (1,1) (4,N)

    (1,N)

    (0,N)

    (1,1)

    (1,1)(3,N)

  • 7/29/2019 Lt5 ERconstraints EER

    12/25

  • 7/29/2019 Lt5 ERconstraints EER

    13/25

    13

    Why EER

    The ER modeling concepts are notsufficient for representing new databaseapplications, which have more complex

    requirements than do the more traditionalapplications.

    Additional semantic data modelingconcepts must be used to represent theserequirements as accurately and clearly aspossible.

  • 7/29/2019 Lt5 ERconstraints EER

    14/25

    EER

    EER model concepts includes

    All modeling concepts of basic ER

    Additional concepts: subclasses/superclasses

    specialization/generalization

    categories (UNION types)

    attribute and relationship inheritance

    These are fundamental to conceptual modeling

    The additional EER concepts are used to modelapplications more completely and moreaccurately

    EER includes some object-oriented concepts,such as inheritance

  • 7/29/2019 Lt5 ERconstraints EER

    15/25

    EER Modeling

    Sub classes, Super classes andInheritance

    Specialization and Generalization

    Constraints and Characteristics of

    Specialization and Generalization

    Modeling of UNION Types Using

    Categories

  • 7/29/2019 Lt5 ERconstraints EER

    16/25

    Sub classes and Super classes

    EMPLOYE

    E

    SECRETARY

    ENGINEER

    TECHNICIAN

    SALARIED_EMPLOYEE

    HOURLY_EMPLOYEE

    Every entity that is a member of one of thesesubgroupings is also an employee

    Superclasses: EMPLOYEE

    Subclasses: SECRETARY,ENGINEER,

    TECHNICIAN,

    SALARIED_EMPLOYEE,

    HOURLY_EMPLOYEE

    An entity type may have additional

    meaningful subgroupings of its entities

    d

    d

  • 7/29/2019 Lt5 ERconstraints EER

    17/25

    17

    Example

    SECRETARY

    d

    TECHNICIAN

    ENGINEER

    d

    SALARIED_EMP

    HOURLY_EMP

    MANAGER

    EMPLOYEE

    MANAGES

    PROJECT

    BELONGS_TO

    TRADE_UNION

    WORKSDEPARTMENT

    EMPLOYEE: WORKS

    SECRETARY: WORKSTECHNICIAN: WORKSENGINEER: WORKSMANAGER: WORKS, MANAGESSALARIED_EMP: WORKSHOURLY_EMP: WORKS, BELONGS_TO

    TypingSpeed TGrade

    EngType

    FnameLname SSN

    Addr

  • 7/29/2019 Lt5 ERconstraints EER

    18/25

    18

    Why class/subclass relationships andspecializations

    Certain attributes may apply to some butnot all entities of the super class. A subclass is defined in order to group the

    entities to which these attributes apply.The members of the subclass may still share

    the majority of their attributes with the othermembers of the super class.

    EMPLOYEE (Name, SSN, BirthDate, Address)SECRETARY (Name, SSN, BirthDate, Address,TypingSpeed)

    ENGINEER (Name, SSN, BirthDate, Address,EngineerType)

    TECHNICIAN (Name, SSN, BirthDate, Address,TGrade)

  • 7/29/2019 Lt5 ERconstraints EER

    19/25

    19

    Why need class/subclass relationshipsand specializations

    Some relationship types may be

    participated in only by entities thatare members of the subclass.

  • 7/29/2019 Lt5 ERconstraints EER

    20/25

    20

    Sub classes vs. Super classes

    The set of entities in each sub class is a subsetof the entities that belong to EMPLOYEE

    Each is called a subclass of EMPLOYEE

    EMPLOYEE is the super class for each of thesesubclasses

    The relationship between a super class and anyone of its subclass is called a super class/subclass or class/sub class relationship.

    e.g., EMPLOYEE/SECRETARY andEMPLOYEE/TECHNICIAN are two class/subclassrelationships.

  • 7/29/2019 Lt5 ERconstraints EER

    21/25

    Properties of Super classes andSub classes

    A member entity of the subclassrepresents the same real-world entityas some member of the super class.

    The subclass member is the same as the

    entity in the super class, but in a distinctspecific role.

    When implementing a super class/subclassrelationship, a member of the subclassmay be represented as a distinctdatabase object a distinct record thatis related via the key attribute to its superclass entity.

  • 7/29/2019 Lt5 ERconstraints EER

    22/25

    22

    Properties of Super classes and Subclasses (cont.)

    An entity CANNOT exist in the DB merelyby being a member of a subclass. It mustalso be a member of the super class.

    An entity can be a member of more thanone subclass. Example: A salaried employee who is also an engineer belongs

    to the two subclasses ENGINEER and SALARIED_EMPLOYEE

    It is not necessary that every entity in asuper class be a member of somesubclass Example: A technical writer is an employee but does not

    belong to any subclasses.

  • 7/29/2019 Lt5 ERconstraints EER

    23/25

    23

    Type inheritance

    The type of an entity is defined by theattributes it possesses and therelationship types which it participates.

    An entity that is a member of a subclassinherits all the attributes of the entity asa member of the super class, as well as allthe relationships in which the super classparticipates.

  • 7/29/2019 Lt5 ERconstraints EER

    24/25

    24

    Example

    EMPLOYEE

    SECRETARYTECHNICIAN

    d

    Fname

    Lname

    SSN

    TypingSpeed

    TGrade

    ENGINEER

    EngType

    SECRETARYFname, Lname, SSN, Addr

    TypingSpeedTECHNICIAN

    Fname, Lname, SSN, Addr, TGrade

    ENGINEERFname, Lname, SSN, Addr,EngType

    Addr EMPLOYEEFname, Lname, SSN,Addr

  • 7/29/2019 Lt5 ERconstraints EER

    25/25

    25

    Example

    SECRETARY

    d

    TECHNICIAN

    ENGINEER

    d

    SALARIED_EMP

    HOURLY_EMP

    MANAGER

    EMPLOYEE

    MANAGES

    PROJECT

    BELONGS_TO

    TRADE_UNION

    WORKSDEPARTMENT

    Entity Type: Relationship TypeEMPLOYEE: WORKSSECRETARY: WORKS

    TECHNICIAN: WORKSENGINEER: WORKSMANAGER: WORKS, MANAGESSALARIED_EMP: WORKSHOURLY_EMP: WORKS, BELONGS_TO

    TypingSpee

    d TGradeEngType