Database Management.pptx

Embed Size (px)

Citation preview

  • 8/14/2019 Database Management.pptx

    1/27

  • 8/14/2019 Database Management.pptx

    2/27

    Third Normal Form

    Problems can still existwith tables that are in

    second normal form.Consider the following

    Customer table:Customer ( CustomerNum, CustomerName, Balance, CreditLimit, RepNum,

    LastName, FirstName)

  • 8/14/2019 Database Management.pptx

    3/27

    The functional dependenciesin this tale are as follows:

    CustomerNum >

    CustomerNAme, Balance,

    CreditLimit, RepNum,LastName, FirstName

    RepNum >LastName, FirstName

  • 8/14/2019 Database Management.pptx

    4/27

    CustomerNum determines all

    the other columns.

    In addition, RepNumdetermines LastName and

    FirstNAme.

  • 8/14/2019 Database Management.pptx

    5/27

    When the primary key of a

    table is a single column, the

    table is automatically in second

    normal form. Thus, the

    Customer table is in second

    normal form.

  • 8/14/2019 Database Management.pptx

    6/27

    Num Name Limit Num Name Name

    148 AlsApplianceand Sport

    $ 6550 $7500 20 Kaiser Valerie

    282 BrookingsDirect

    $431.20 $10000 35 Hull Richard

    356 Fergusons $5785 $7500 65 Perez Juan

    408 TheEverything

    Shop

    $5285.25

    $5000.00

    35 Hull Richard

    524 Klines $12762 $15000 20 Kaiser Valerie

    608 JohnsonsDepartment

    Store

    $2106 $10000 65 Perez Juan

  • 8/14/2019 Database Management.pptx

    7/27

    687 LeesSport

    andAppliance

    $2851 $5000 35 Hull Richard

    725 DeerfieldsFour

    Seasons

    $248 $7500 35 Hull Richard

    842 AllSeason

    $8221 $7500.00

    20 Kaiser Valerie

    This redundancy creates the same set of problems that you

    examined in the first normal form Orders table.

    In addition to the problem of wasted space, you have similar

    update anomalies as follows:

  • 8/14/2019 Database Management.pptx

    8/27

    1. Updates

    A change to the name of a

    sales rep requires not one

    change to the table, but several,

    making the update process

    cumbersome.

  • 8/14/2019 Database Management.pptx

    9/27

    2. Inconsistent data.

    There is nothing about the

    design that would prohibit a salesrep from having two differentnames in the database. In fact, ifthe same sales rep represents 20customers, he or she could have

    20 different names in thedatabase.

  • 8/14/2019 Database Management.pptx

    10/27

    3. Additions

    In order to add sales rep 87

    (Mary Daniels) to the database, shemust already represent at least onecustomer. IF she has not yet been

    assigned any customers, you mustadd her record and create a fictitiouscustomer for her to represent. Again,

    this is not a desirable solution to theproblem.

  • 8/14/2019 Database Management.pptx

    11/27

    4. Deletions

    If you deleted all the

    customers of sales rep 35 fromthe database, you would lose

    all information concerning

    sales rep 35.

  • 8/14/2019 Database Management.pptx

    12/27

    These update anomalies are due

    to the fact that RepNum

    determines LastName andFirstName, but RepNum is not the

    primary key. As a result, the sameRepNum and consequently the

    same LastName and FirstName

    can appear on many different

    rows.

  • 8/14/2019 Database Management.pptx

    13/27

  • 8/14/2019 Database Management.pptx

    14/27

    Customer Table

    It is not in third normal form.The following method corrects the deficiency in the

    Customer table and in all tables having similar

    deficiencies.

    For each determinant that is nota candidate key, remove from

    the table the columns thatdepend on this determinant.

  • 8/14/2019 Database Management.pptx

    15/27

    Create a New table containing al

    the columns from the original

    table that depend on this

    determinant.

    Make the determinant the

    primary key of this new table.

    C t

  • 8/14/2019 Database Management.pptx

    16/27

    Customer

    NumCustomerName Balanc

    e

    CreditLimit

    RepNum

    148 Als Appliance and

    Sport

    $6550.00 $7500.00 20

    282 Brookings Direct $431.40 $10000.00 35

    356 Fergusons $5785.00 $7500.00 65

    408 The Everything Shop $5825.25 $5000.00 35

    462 Bargains Galore $3412.00 $10000.00 65

    524 Klines $12762.00 $15000.00 20

    608 JohnsonsDepartment Store

    $2106.00 $10000.00 65

    687 Lees Sport andAppliance

    $2851.00 $5000.00 35

    725 Deerfields FourSeasons

    $248.00 $7500.00 35

  • 8/14/2019 Database Management.pptx

    17/27

    RepNum LastName FirstName

    20 Kaiser Valerie

    35 Hull Richard65 Perez Juan

    Conversion to third normal form

    I t D iti

  • 8/14/2019 Database Management.pptx

    18/27

    Incorrect Decompositions

    It is important to note that the

    decomposition of a table into twoor more third normal form tablesmust be accomplished by themethod indicated in the previoussection, even though there are

    other possibilities that at firstglance might seem to belegitimate.

  • 8/14/2019 Database Management.pptx

    19/27

    C t C t N l C ditLi

  • 8/14/2019 Database Management.pptx

    20/27

    Customer

    NumCustomerName Balanc

    e

    CreditLimit

    RepNum

    148 Als Appliance and

    Sport

    $6550.00 $7500.00 20

    282 Brookings Direct $431.40 $10000.00 35

    356 Fergusons $5785.00 $7500.00 65

    408 The Everything Shop $5825.25 $5000.00 35

    462 Bargains Galore $3412.00 $10000.00 65

    524 Klines $12762.00 $15000.00 20

    608 JohnsonsDepartment Store

    $2106.00 $10000.00 65

    687 Lees Sport andAppliance

    $2851.00 $5000.00 35

    725 Deerfields FourSeasons

    $248.00 $7500.00 35

    C t N L tN Fi tN

  • 8/14/2019 Database Management.pptx

    21/27

    CustomerNum LastName FirstName

    148 Kaiser Valerie

    282 Hull Richard356 Perez Juan

    408 Hull Richard

    462 Perez Juan

    524 Kaiser Valerie

    608 Perez Juan

    687 Hull Richard

    725 Hull Richard

    842 Kaiser Valerie

  • 8/14/2019 Database Management.pptx

    22/27

    Consider, for example, the

    redundancy in the storage of sales

    reps names, the problem

    encountered in changing the name

    of a sales rep and the difficulty of

    adding a new sales rep who

    represents no customers.

  • 8/14/2019 Database Management.pptx

    23/27

    In addition, because the rep

    number and names are in

    different tables, you have actuallysplit a functional dependence

    across two different tables. Thus,this seemingly valid

    decomposition is definitely not a

    desirable way to create third

    normal form tables.

  • 8/14/2019 Database Management.pptx

    24/27

    There is another decomposition

    that you might choose.

    Customer (CustomerNum,

    CustomerName, Balance,

    CreditLimit, LastName,

    FirstName)

    CustomerN CustomerName B l CreditLim LN FN

  • 8/14/2019 Database Management.pptx

    25/27

    CustomerN

    umCustomerName Balan

    ce

    CreditLimit

    LN FN

    148 Als Appliance andSport

    $6550.00 $7500.00 Kaiser Valerie

    282 Brookings Direct $431.40 $10000.00 Hull Richard

    356 Fergusons $5785.00 $7500.00 Perez Juan

    408 The Everything Shop $5825.25 $5000.00

    HullRichar

    d

    462 Bargains Galore $3412.00 $10000.00 Perez Juan

    524 Klines $12762.00 $15000.00 Kaiser Valerie

    608 JohnsonsDepartment Store

    $2106.00 $10000.00 Perez Juan

    687 Lees Sport andAppliance

    $2851.00 $5000.00 Hull Richard

    725 Deerfields Four

    Seasons

    $248.00 $7500.00

    Hull

    Richar

    d

  • 8/14/2019 Database Management.pptx

    26/27

    Second incorrect decomposition of

    the Customer Table

    RepNum LastName FirstName

    20 Kaiser Valerie

    35 Hull Richard

    65 Perez Juan

  • 8/14/2019 Database Management.pptx

    27/27