ch7-abbrev-part1

download ch7-abbrev-part1

of 30

Transcript of ch7-abbrev-part1

  • 7/28/2019 ch7-abbrev-part1

    1/30

    Database System Concepts, 6th Ed.

    Silberschatz, Korth and Sudarshan

    See www.db-book.com for conditions on re-use

    Chapter 7: Entity-Relationship Model

    http://www.db-book.com/http://www.db-book.com/http://www.db-book.com/http://www.db-book.com/
  • 7/28/2019 ch7-abbrev-part1

    2/30

    Silberschatz, Korth and Sudarshan7.2Database System Concepts - 6th Edition

    Chapter 7: Entity-Relationship Model

    Design Process

    Modeling

    Constraints

    E-R Diagram

    Design Issues Weak Entity Sets

    Extended E-R Features

    Design of the Bank Database

    Reduction to Relation Schemas Database Design

    UML

  • 7/28/2019 ch7-abbrev-part1

    3/30

    Silberschatz, Korth and Sudarshan7.3Database System Concepts - 6th Edition

    Modeling

    A database can be modeled as:

    a collection of entities,

    relationship among entities.

    An entityis an object that exists and is distinguishable fromother objects.

    Example: specific person, company, event, plant

    Entities have attributes

    Example: people have names and addresses

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

    same properties.

    Example: set of all persons, companies, trees, holidays

  • 7/28/2019 ch7-abbrev-part1

    4/30

    Silberschatz, Korth and Sudarshan7.4Database System Concepts - 6th Edition

    Entity Sets ins t ructorand student

    ID name ID name

  • 7/28/2019 ch7-abbrev-part1

    5/30

    Silberschatz, Korth and Sudarshan7.5Database System Concepts - 6th Edition

    Keys

    A super key of an entity set is a set of one or moreattributes whose values uniquely determine each entity.

    A candidate key of an entity set is a minimal super key

    ID is candidate key of instructor

    course_idis candidate key of course

    Although several candidate keys may exist, one of thecandidate keys is selected to be the primary key.

  • 7/28/2019 ch7-abbrev-part1

    6/30

    Silberschatz, Korth and Sudarshan7.6Database System Concepts - 6th Edition

    Relationship Sets

    A relationship is an association among several entities

    Example:44553 (Peltier) advisor 22222 (Einstein)

    studententity relationship set instructorentity

    A relationship set is a mathematical relation among n 2

    entities, each taken from entity sets{(e1, e2, en) | e1 E1, e2 E2, , en En}

    where (e1, e2, , en) is a relationship

    Example:

    (44553,22222) advisor

  • 7/28/2019 ch7-abbrev-part1

    7/30Silberschatz, Korth and Sudarshan7.7Database System Concepts - 6th Edition

    Relationship Set advisor

  • 7/28/2019 ch7-abbrev-part1

    8/30Silberschatz, Korth and Sudarshan7.8Database System Concepts - 6th Edition

    E-R Diagrams

    Rectangles represent entity sets.

    Diamonds represent relationship sets.

    Attributes listed inside entity rectangle

    Underline indicates primary key attributes

    Note: ER diagram notation in 6th edition of Database SystemConcepts changed from earlier editions; now based on UML classdiagram notation with some modifications.

  • 7/28/2019 ch7-abbrev-part1

    9/30Silberschatz, Korth and Sudarshan7.9Database System Concepts - 6th Edition

    Relationship Sets With Attributes

    An attribute can also be property of a relationship set.

    For instance, the advisor relationship set between entity setsinstructor and student may have the attribute date

    E.g. date may track when the student started beingassociated with the advisor

  • 7/28/2019 ch7-abbrev-part1

    10/30Silberschatz, Korth and Sudarshan7.10Database System Concepts - 6th Edition

    Relationship Sets with Attributes

  • 7/28/2019 ch7-abbrev-part1

    11/30Silberschatz, Korth and Sudarshan7.11Database System Concepts - 6th Edition

    Attributes

    An entity is represented by a set of attributes, that is descriptiveproperties possessed by all members of an entity set.

    Example:

    instructor = (ID, name, street, city, salary)course= (course_id, title, credits)

    Domain the set of permitted values for each attribute

    Attribute types:

    Simple and composite attributes.

    Single-valued and multivalued attributes

    Example: multivalued attribute:phone_numbers

    Derived attributes

    Can be computed from other attributes

    Example: age, given date_of_birth

  • 7/28/2019 ch7-abbrev-part1

    12/30Silberschatz, Korth and Sudarshan7.12Database System Concepts - 6th Edition

    Composite Attributes

  • 7/28/2019 ch7-abbrev-part1

    13/30Silberschatz, Korth and Sudarshan7.13Database System Concepts - 6th Edition

    Entity With Composite, Multivalued, and DerivedAttributes

    composite

    multivalued

    derived

  • 7/28/2019 ch7-abbrev-part1

    14/30Silberschatz, Korth and Sudarshan7.14Database System Concepts - 6th Edition

    Degree of a Relationship Set

    binary relationship

    involve two entity sets (or degree two).

    most relationship sets in a database system are binary.

    Relationships between more than two entity sets are rare.Most relationships are binary. (More on this later.)

    Example: students work on researchprojects under theguidance of an instructor.

    relationshipproj_guide is a ternary relationship between

    instructor, student, andproject

  • 7/28/2019 ch7-abbrev-part1

    15/30Silberschatz, Korth and Sudarshan7.15Database System Concepts - 6th Edition

    E-R Diagram with a Ternary Relationship

  • 7/28/2019 ch7-abbrev-part1

    16/30Silberschatz, Korth and Sudarshan7.16Database System Concepts - 6th Edition

    Quiz Time

    Quiz Q1: Suppose are given a person entity set, and we wish torepresent the relationship between people and their father andmother. Which of these would be an appropriate representation, iffor some people we only know either their father or their motherbut not both?

    (1) two binary relationships, father and mother, between persons(2) a ternary relationship between persons, linking a person to

    his/her father and mother(3) an entity set parent, linked by three relationships to person,

    representing person, father and mother.

    (4) an entity set with attributes person, father and mother

  • 7/28/2019 ch7-abbrev-part1

    17/30Silberschatz, Korth and Sudarshan7.17Database System Concepts - 6th Edition

    Mapping Cardinality Constraints

    Express the number of entities to which another entity can be

    associated via a relationship set. Most useful in describing binary relationship sets.

    For a binary relationship set the mapping cardinality must beone of the following types:

    One to one One to many

    Many to one

    Many to many

  • 7/28/2019 ch7-abbrev-part1

    18/30Silberschatz, Korth and Sudarshan7.18Database System Concepts - 6th Edition

    Mapping Cardinalities

    One to one One to many

    Note: Some elements inA and B may not be mapped to anyelements in the other set

  • 7/28/2019 ch7-abbrev-part1

    19/30Silberschatz, Korth and Sudarshan7.19Database System Concepts - 6th Edition

    Mapping Cardinalities

    Many toone

    Many to many

    Note: Some elements in A and B may not be mapped to anyelements in the other set

  • 7/28/2019 ch7-abbrev-part1

    20/30Silberschatz, Korth and Sudarshan7.20Database System Concepts - 6th Edition

    ER Notation for Cardinality Constraints

    We express cardinality constraints by drawing either

    a directed line (), signifying one, or

    an undirected line (), signifying many,

    between the relationship set and the entity set.

    One-to-one relationship:

    A student is associated with at most one instructorvia therelationship advisor

    A studentis associated with at most one departmentvia

    stud_dept

  • 7/28/2019 ch7-abbrev-part1

    21/30Silberschatz, Korth and Sudarshan7.21Database System Concepts - 6th Edition

    One-to-One Relationship

    one-to-one relationship between an instructorand a student

    an instructor is associated with at most one student viaadvisor

    and a student is associated with at most one instructorvia advisor

  • 7/28/2019 ch7-abbrev-part1

    22/30Silberschatz, Korth and Sudarshan7.22Database System Concepts - 6th Edition

    One-to-Many Relationship

    one-to-many relationship between an instructorand a student

    an instructor is associated with several (including 0)students via advisor

    a student is associated with at most one instructor viaadvisor

  • 7/28/2019 ch7-abbrev-part1

    23/30

    Silberschatz, Korth and Sudarshan7.23Database System Concepts - 6th Edition

    Many-to-One Relationships

    In a many-to-one relationship between an instructorand a

    student,

    an instructor is associated with at most one student via

    advisor,

    and a student is associated with several (including 0)

    instructors via advisor

  • 7/28/2019 ch7-abbrev-part1

    24/30

    Silberschatz, Korth and Sudarshan7.24Database System Concepts - 6th Edition

    Many-to-Many Relationship

    An instructor is associated with several (possibly 0)

    students via advisor A student is associated with several (possibly 0)

    instructors via advisor

    Participation of an Entity Set in a

  • 7/28/2019 ch7-abbrev-part1

    25/30

    Silberschatz, Korth and Sudarshan7.25Database System Concepts - 6th Edition

    Participation of an Entity Set in aRelationship Set

    Total participation (indicated by double line): every entity in the

    entity set participates in at least one relationship in the relationshipset

    E.g. participation of section in sec_course is total

    every must have an associated course

    Partial participation: some entities may not participate in anyrelationship in the relationship set

    Example: participation of instructorin advisoris partial

    Alternative Notation for Cardinality

  • 7/28/2019 ch7-abbrev-part1

    26/30

    Silberschatz, Korth and Sudarshan7.26Database System Concepts - 6th Edition

    Alternative Notation for CardinalityLimits

    Cardinality limits can also express participation constraints Number on line represents how many times the entity can

    participate in the relationship

    Quiz Q2: The above relationship is(1) Many to one from instructor to student(2) One to many from instructor to student(3) One to one(4) many to many

  • 7/28/2019 ch7-abbrev-part1

    27/30

    Silberschatz, Korth and Sudarshan7.27Database System Concepts - 6th Edition

    Keys for Relationship Sets

    The combination of primary keys of the participating entity sets

    forms a super key of a relationship set.

    (s_id, i_id) is the super key of advisor

    NOTE: this means a pair of ent i ty sets can have at most

    one relat ions hip in a part icular relationship set.

    Example: if we wish to track multiple meeting datesbetween a student and her advisor, we cannot haveseparate relationship instances for each meeting.

    We can use a multivalued attribute though

    Must consider the mapping cardinality of the relationship setwhen deciding what are the candidate keys

    Need to consider semantics of relationship set in selecting the

    primary key in case of more than one candidate key

  • 7/28/2019 ch7-abbrev-part1

    28/30

    Silberschatz, Korth and Sudarshan7.28Database System Concepts - 6th Edition

    Redundant Attributes

    Suppose we have entity sets

    instructor, with attributes including dept_name

    department

    and a relationship

    inst_deptrelating instructorand department

    Attribute dept_name in entity instructoris redundant since thereis an explicit relationship inst_deptwhich relates instructors todepartments

    The attribute replicates information present in therelationship, and should be removed from instructor

    BUT: when converting back to tables, in some cases theattribute gets reintroduced, as we will see.

  • 7/28/2019 ch7-abbrev-part1

    29/30

    Silberschatz, Korth and Sudarshan7.29Database System Concepts - 6th Edition

    Roles

    Entity sets of a relationship need not be distinct

    Each occurrence of an entity set plays a role in the

    relationship

    The labels course_id and prereq_id are called roles.

  • 7/28/2019 ch7-abbrev-part1

    30/30

    Database System Concepts, 6th Ed.

    Silberschatz, Korth and SudarshanSee www.db-book.com for conditions on re-use

    How about doing an ER designinteractively on the board?

    Suggest an application to be modeled.

    http://www.db-book.com/http://www.db-book.com/http://www.db-book.com/http://www.db-book.com/