chapter3-relational database2

download chapter3-relational database2

of 27

Transcript of chapter3-relational database2

  • 8/14/2019 chapter3-relational database2

    1/27

    Chapter 3The Relational Database Model

    (Part 2)

  • 8/14/2019 chapter3-relational database2

    2/27

    OBJECTIVE:

    After learn this chapter, students will

    Explain the logical view of the data in relational database model

    Define the relational models basic components.

    Explain how entities and their attributes are organized into

    tables.

    Analyses the difference between data dictionary and system

    catalog

    Explain how data redundancy is handled in the relational

    database model.

  • 8/14/2019 chapter3-relational database2

    3/27

    A Logical View of Data Relational database models structural and

    data independence enables us to view data

    logically rather than physically.

    The logical view allows a simpler fileconcept of data storage.

    The use of logically independent tables is

    easier to understand.

    Logical simplicity yields simpler and more

    effective database design methodologies.

  • 8/14/2019 chapter3-relational database2

    4/27

    A Logical View of Data Entities and Attributes

    An entity is a person, place, event, or thingfor which we intend to collect data.

    University -- Students, Faculty Members, Courses

    Airlines -- Pilots, Aircraft, Routes, Suppliers

    Each entity has certain characteristicsknown as attributes.

    Student -- Student Number, Name, GPA, Date ofEnrollment, Data of Birth, Home Address, Phone

    Number, Major

    Aircraft -- Aircraft Number, Date of Last

    Maintenance, Total Hours Flown, Hours Flownsince Last Maintenance

  • 8/14/2019 chapter3-relational database2

    5/27

    A Logical View of Data

    Entities and Attributes

    A grouping of related entities becomes an

    entity set.

    The STUDENT entity set contains all studententities.

    The FACULTY entity set contains all facultyentities.

    The AIRCRAFT entity set contains all aircraftentities.

  • 8/14/2019 chapter3-relational database2

    6/27

    A Logical View of Data

    Tables and Their Characteristics

    A table contains a group of relatedentities -- i.e. an entity set.

    The terms entity set and table are often

    used interchangeably.

    A table is also called a relation.

  • 8/14/2019 chapter3-relational database2

    7/27

    Keys Controlled redundancy (shared common

    attributes) makes the relational databasework.

    Theprimary key of one table appears againas the link (foreign key) in another table.

    If the foreign key contains either matchingvalues or nulls, the table(s) that make use ofsuch a foreign key are said to exhibit

    referential integrity.

  • 8/14/2019 chapter3-relational database2

    8/27

    Keys

    Akey helps define entity relationships.

    The keys role is based on a concept known asdetermination, which is used in the definition offunctional dependence.

    The attribute B is functionally dependent on A if Adetermines B.

    An attribute that is part of a key is known as a keyattribute.

    A multi-attribute key is known as a composite key.

    If the attribute (B) is functionally dependent on acomposite key (A) but not on any subset of thatcomposite key, the attribute (B) is fully functionallydependent on (A).

  • 8/14/2019 chapter3-relational database2

    9/27

    Relational Database Keys

    Table 2.3

  • 8/14/2019 chapter3-relational database2

    10/27

    Integrity Rules Revisited

    Table 2.4

  • 8/14/2019 chapter3-relational database2

    11/27

    The Data Dictionary and

    the System Catalog Data dictionary contains metadata to provide detailed accounting of

    all tables within the database.

    System catalog is a very detailed system data dictionary that describes

    all objects within the database.

    System catalog is a system-created database whose tables store

    the database characteristics and contents.

    System catalog tables can be queried just like any other tables.

    System catalog automatically produces databasedocumentation.

  • 8/14/2019 chapter3-relational database2

    12/27

    A Sample Data Dictionary

    Table 2.6

  • 8/14/2019 chapter3-relational database2

    13/27

    Relationships within the Relational

    Database

    E-R Diagram (ERD)

    Rectangles are used to represent entities.

    Entity names are nouns and capitalized.

    Diamonds are used to represent therelationship(s) between the entities.

    The number 1 is used to represent the 1side of the relationship.

    The letter M is used to represent the many

    sides of the relationship.

  • 8/14/2019 chapter3-relational database2

    14/27

    The Relationship Between Painter and Painting

    Figure 2.17

  • 8/14/2019 chapter3-relational database2

    15/27

    An Alternate Way to Present the Relationship

    Between Painter and Painting

    Figure 2.18

  • 8/14/2019 chapter3-relational database2

    16/27

    A 1:M Relationship: The CH2_MUSEUM Database

    Figure 2.19

  • 8/14/2019 chapter3-relational database2

    17/27

    The 1:M Relationship Between Course and Class

    Figure 2.20

  • 8/14/2019 chapter3-relational database2

    18/27

  • 8/14/2019 chapter3-relational database2

    19/27

    The M:N Relationship Between Student and Class

    Figure 2.22

  • 8/14/2019 chapter3-relational database2

    20/27

    Table 2.7

    Sample Student Enrollment Data

  • 8/14/2019 chapter3-relational database2

    21/27

    A Many-to-Many Relationship Between Student and Class

    Figure 2.23

  • 8/14/2019 chapter3-relational database2

    22/27

  • 8/14/2019 chapter3-relational database2

    23/27

    Changing the M:N Relationship to Two 1:M Relationships

    Figure 2.25

  • 8/14/2019 chapter3-relational database2

    24/27

    The Expanded Entity Relationship Model

    Figure 2.26

  • 8/14/2019 chapter3-relational database2

    25/27

    The Relational Schema for the Entity Relationship Diagram

    in Figure 2.26

    Figure 2.27

  • 8/14/2019 chapter3-relational database2

    26/27

    Data Redundancy Revisited

    Proper use of foreign keys is crucial toexercising data redundancy control.

    Database designers must reconcile threeoften contradictory requirements: designelegance, processing speed, and informationrequirements. (Chapter 4)

    Proper data warehousing design evenrequires carefully defined and controlleddata redundancies, to function properly.

    (Chapter 13)

  • 8/14/2019 chapter3-relational database2

    27/27

    The redundancy is crucial to the systems success.

    Copying the product price from the PRODUCT table

    to the LINE table means that it is possible to

    maintain the historical accuracy of the transactions.

    Figure 2.29

    The Relational Schema for the Invoicing System in Figure 2.28