+ All Categories
Home > Documents > Multi Valued Dependencies & 4NF - Good

Multi Valued Dependencies & 4NF - Good

Date post: 05-Apr-2018
Category:
Upload: ram-rao
View: 226 times
Download: 0 times
Share this document with a friend

of 30

Transcript
  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    1/30

    Multi-valued Dependencies and

    4

    th

    n

    th

    N rm l F rm

    Louis D. Nel 2010 1Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    2/30

    Multi-valued Dependencies

    Consider the situation of bank customers whopossibly have multiple addresses and multipleaccounts

    LOANSLOAN NO CUSTOMER STREET CITY_

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    Louis D. Nel 2010 2Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    3/30

    Suppose Sue takes out another loan (#113) wecould add the following tuple to the LOANS table

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    113 Sue Elgin Ottawa

    Problem: Which of Sues addresses do we enter inthe table? (Can we insist that both appear?)

    Louis D. Nel 2010 3Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    4/30

    We want to consider the table shown below to bein a bad state potentially dangerous

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    113 Sue Elgin Ottawa

    How can this table be fixed?

    What is the key for this table?

    Louis D. Nel 2010 4Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    5/30

    Solution 1) add another tuple

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    113 Sue Elgin Ottawa

    113 Sue Eagleson Kanata

    Louis D. Nel 2010 5Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    6/30

    Solution 2) Decompose the relation

    LOANS

    LOAN_NO CUSTOMER

    101 Sue

    ADDRESS

    CUSTOMER STREET CITY

    112 Frank

    113 SueSue Eagleson Kanata

    Frank Bank Ottawa

    Louis D. Nel 2010 6Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    7/30

    Decomposing The Table

    What would guide the decomposition

    Which of the functional dependency based normalforms does the table appear to satisfy?

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    113 Sue Eagleson Kanata

    Louis D. Nel 2010 7Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    8/30

    Decomposing The Table

    1nf because there is a key

    2nf because there is not attribute partiallydependent on the key

    determining a non-key attribute

    BCNF because no part of the key appears toepen on anot er attr ute

    LOANS

    LOAN NO CUSTOMER STREET CITY_

    101 Sue Elgin Ottawa101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    Louis D. Nel 2010 8Design with Normal Forms 8 -COMP 3005

    113 Sue Eagleson Kanata

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    9/30

    Couldnt we just require?

    CUSTOMER -> ADDRESSCUSTOMER -> LOAN

    No because customers can have multiple addressesand multiple loans

    Louis D. Nel 2010 9Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    10/30

    What is the problem?

    The problem seems to be occurring because theta e represents two n epen ent :

    relationships being represented in the same table.

    Customers can have multi le loans and alsoindependently, customers can have multipleaddresses.

    relationship appears in each table can fix theproblem, but what formal constraint would guide

    Louis D. Nel 2010 10Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    11/30

    The multi-valued dependency

    CUSTOMER ->-> ADDRESS

    specifies that a customer can have multiple

    It does not rule out the possibility of multiple

    addresses, instead specifies that if a tuplecontains one address, other tuples may need tobe added with the other

    Louis D. Nel 2010 11Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    12/30

    Multi-valued dependencies are a consequence ofrst orma orm -attr utes cannot e mu t -

    valued

    If we do have two multi-valued attributes in arelation (e.g. loan, address) we have to repeatever value of one with ever value of the other ifwe want to keep things consistent

    -says that, in effect, that each loan must appearwith each address

    Louis D. Nel 2010 12Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    13/30

    Defn Multi-valued Dependency

    For a relation r(R) with attribute subsets X and Y,the multi-valued de endenc X->-> Y re uires that

    if two tuples t1 and t2 exist with t1[X] = t2[X] thentwo tuples t3 and t4 must also exist with

    t3[X] = t4[X] = t1[X] = t2[X]t3[Y] = t1[Y] and t4[Y] = t2[Y]t3 R- XY = t2 R- XY and t4 R- XY = t1 R- XY

    t1 t2 t3 t4 need not be distinct

    Louis D. Nel 2010 13Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    14/30

    Defn Multi-valued Dependency

    If t1 and t2 exist with t1[X] = t2[X] then t3 and t4must exist witht3[X] = t4[X] = t1[X] = t2[X]t3[Y] = t1[Y] and t4[Y] = t2[Y]t3[R-(XY)] = t2[R-(XY)] and t4[R-(XY)] = t1[R-(XY)]

    ADDRESS 1LOAN 1

    CUSTOMER

    _

    ADDRESS_2LOAN_2

    _

    X

    ADDRESS_3LOAN_3Y R - (XY)

    Louis D. Nel 2010 14Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    15/30

    Example

    If t1 and t2 exist with t1[X] = t2[X] then t3 and t4 must existwitht3[X] = t4[X] = t1[X] = t2[X]

    = =

    t3[R-(XY)] = t2[R-(XY)] and t4[R-(XY)] = t1[R-(XY)]

    Sue

    Ottawa

    113

    101Given tuples

    Then so must

    Sue

    Kanata113

    exist

    Louis D. Nel 2010 15Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    16/30

    Does CUSTOMER ->-> ADDRESS hold here?

    LOANS

    _

    101 Sue Elgin Ottawa101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    t1

    t4

    113 Sue Elgin Ottawa

    There is no t3 for which agrees with t1 address

    If t1 and t2 exist with t1[X] = t2[X] then t3 and t4 must exist

    and t2 loan -so no

    wt3[X] = t4[X] = t1[X] = t2[X]t3[Y] = t1[Y] and t4[Y] = t2[Y]t3 R- XY = t2 R- XY and t4 R- XY = t1 R- XY

    Louis D. Nel 2010 16Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    17/30

    Does CUSTOMER ->-> ADDRESS hold here?

    LOANS

    LOAN N CUSTOME STREET CITY

    t1t4

    _

    101 Sue Elgin Ottawa

    101 Sue Eagleso Kanata

    112 Frank Bank Ottawa

    t2t3113 Sue Elgin Ottawa

    113 Sue Eagleso Kanata

    111 John Riverside Ottawas1 s3

    If t1 and t2 exist with t1[X] = t2[X] then t3 and t4 must exist

    wt3[X] = t4[X] = t1[X] = t2[X]t3[Y] = t1[Y] and t4[Y] = t2[Y]t3 R- XY = t2 R- XY and t4 R- XY = t1 R- XY

    Louis D. Nel 2010 17Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    18/30

    Whenever two independent 1:N relationships X:Yand X:Z are mixed in the same relation a multi-valued de endenc could arise

    e.g. a customers address is independent of the,several of each

    Louis D. Nel 2010 18Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    19/30

    Trivial Multi-valued Dependencies

    If Y is a subset of X, X->->Y

    = , - -

    These are called trivial because they hold in anylegal relation R (and so dont specify anyadditional constraint

    Louis D. Nel 2010 19Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    20/30

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Ea leson Kanata

    112 Frank Bank Ottawa

    113 Sue Elgin Ottawa

    113 Sue Eagleson Kanata

    Which should we specify?

    - - ,CUSTOMER ->-> LOAN

    oes not matter ecause one mp es t e ot er

    Theorem: If X->->Y then X->-> R - X - Y

    Louis D. Nel 2010 20Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    21/30

    Inference Rules for Functional and Multi-valued Dependencies

    For R=(A1,A2, ... ,An) and W, X, Y, Z all subsets of R, thefollowing inference rules hold

    -

    2) If X->Y then XZ -> YZ (augmentation)3) If X->Y and Y->Z, then X->Z (transitive)

    4) If X->->Y, then X->->(R - X - Y) (complementation)

    5) If X->->Y and Z is a subset of W->-> mv augmen a on

    6) If X->->Y, Y->->Z then X->->(Z-Y) (mv transitive)

    - - -,

    8)If X->-> Y and there is a W such thatW INTERSECT Y is empty, W->Z, and

    Louis D. Nel 2010 21Design with Normal Forms 8 -COMP 3005

    s a su se o , en -> coa escence

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    22/30

    Exercise

    Let R=(A, B, C, G, H, I) withMVD = { A->-> B,B ->-> HICG -> H }

    A ->-> CGHI (hint: complementation rule)A ->-> HI (hint: transitivity)

    -

    Louis D. Nel 2010 22Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    23/30

    Do Functional Dependency normal forms help

    Does CUSTOMER ->-> ADDRESS hold here?

    LOANS

    _

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    112 Frank Bank Ottawa

    113 Sue Elgin Ottawa

    This table is in BCNF because no functionaldependencies apply

    Still it is undesirable because of re eated

    information

    Louis D. Nel 2010 23Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    24/30

    Fourth Normal Form

    A relation schema R is in 4NF with respect to a setof dependencies F if, for every nontrivial MVDX->->Y in F+ X is a su erke of R

    Louis D. Nel 2010 24Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    25/30

    Fourth Normal Form

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Ea leson Kanata

    112 Frank Bank Ottawa

    113 Sue Elgin Ottawa

    113 Sue Eagleson Kanata

    F = { CUSTOMER->->STREET,CITYCUSTOMER->->LOAN_NO }

    Violates 4NF because CUSTOMER is not asuperkey

    (and CUSTOMER->->LOAN_NO is non-trivial)

    Louis D. Nel 2010 25Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    26/30

    Decomposition to 4NF

    LOANS

    LOAN_NO CUSTOMER STREET CITY

    101 Sue Elgin Ottawa

    101 Sue Eagleson Kanata

    112 Frank Bank Ottawa113 Sue Elgin Ottawa

    ->-> n

    X->Y not in F

    F = { CUSTOMER->->STREET,CITY

    CUSTOMER->->LOAN_NO }

    LOANS

    CUSTOMER LOAN

    Sue 101

    ADDRESS

    CUSTOMER STREET CITY

    Sue El in Ottawa

    X R - - Y

    Frank 112Sue 113

    Sue Eagleson KanataFrank Bank Ottawa

    Louis D. Nel 2010 26Design with Normal Forms 8 -COMP 3005

    Note: in the decomposed tables both MVD of F are trivial, hence 4NF

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    27/30

    Given a database design situation with functionaland multi-valued dependencies, it isadvanta eous to find a decom osition that is

    4NFLossless JoinDependency Preserving

    ,would be to relax 4NF and go to BCNF or 3NF andlose some dependency preservation

    You never want to relax the lossless-joinconstraint

    Louis D. Nel 2010 27Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    28/30

    Join Dependencies

    It is not always possible to decompose a relation

    join However it may be possible to decompose R into

    more an wo re a ons , , ... , n w c s alossless join decomposition

    These cases are rare and difficult to detect inractice

    Louis D. Nel 2010 28Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    29/30

    Join Dependency

    A join dependency JD(R1, R2, ... ,Rn) specifies aconstraint on instances r(R) that every legalinstance r R should have a lossless oindecomposition into R1, R2, ... ,Rn.

    ,

    JOIN( (r), (r), ... , (r) ) = r

    Louis D. Nel 2010 29Design with Normal Forms 8 -COMP 3005

  • 8/2/2019 Multi Valued Dependencies & 4NF - Good

    30/30

    Fifth Normal Form (Project Normal Form)

    A relation schema R is in 5NF with res ect to a setF of functional, multi-valued, and joindependencies if, for every nontrivial joinde endenc JD R1, R2, ... ,Rn im lied b F, everRi is a superkey of R

    Current practical database design does not pay

    Louis D. Nel 2010 30Design with Normal Forms 8 -COMP 3005


Recommended