ss zg518-l7.ppt

Upload: anup-raghuveer

Post on 04-Jun-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 SS ZG518-L7.ppt

    1/29

    BITSPilaniHyderabad Campus

    Dr.R.GururajCS&IS Dept.

    Database Design & Applications

    (SS ZG 518)

  • 8/14/2019 SS ZG518-L7.ppt

    2/29

    BITS Pilani, Hyderabad Campus

    Lecture Session-7

    Functional Dependencies and Normal Forms (Ch.10 & 11)

    Content

    Introduction to Schema Refinement

    Functional Dependencies

    Inference RulesNormalization

    Normal Forms (1NF and 2NF)

    3 NF and BCNF

    Decomposition requirements

    Lossless join decomposition

    Dependency preserving decomposition

    1 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    3/29

    BITS Pilani, Hyderabad Campus

    A good database design practice is essential to developgood relational schemas at logical level.

    Good database design is needed for:

    Clarity in understanding the database and

    To formulate good queries

    This is achieved by schema refinement.

    Introduction to Database Design

    2 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    4/29

    BITS Pilani, Hyderabad Campus

    Functional Dependency is a constraint between two sets

    of attributes from the database.

    Function DependencyDenoted by X Y between two sets of attributes in R,

    and specifies a constraint on the possible tuples that can

    form a relational instance rof R.

    Values of Y component are determined by X component.

    (or) Y is functionally dependent on X.

    Functional Dependencies

    3 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    5/29

    BITS Pilani, Hyderabad Campus

    XY

    Thus, X functionally determines Y in a relation schema R if

    and only if whenever two tuples of r(R) agree on their X

    values they must necessarily agree on their Y values, butYX is not true (need not be)

    Ex: ssn ename; {ssn, pnumber} Hours

    Note:FDs cannot be inferred. They should be defined by someonewho knows the semantics of the database very well.

    4 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    6/29

    BITS Pilani, Hyderabad Campus

    Dname Dnumber Mgrssn Mgrstartdate

    Department {DnumberDname, Mgrssn,mgrstartdate}

    Essn Pno Hours

    Work_on {Essn, pno} Hours

    Diagrammatic Notation

    5 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    7/29BITS Pilani, Hyderabad Campus

    Rule 1(1R1): (Reflexing)If X Y then X Y otherwise non trivial

    Rule 2(1R2) (Argumentation)

    X Y; then XZ YZ

    Rule 3(1R3) (Transitive)

    X

    Y ; Y

    Z; Then X

    Z;Rule 4(IR4) (Decomposition or projective rule)

    X YZ then X Y; & X Z;

    Rule 5(IR5) (union rule)

    X A; X B ; then X AB

    Rule 6(IR6) (Pseudo transitive)

    X Y ; WY Z; then WX Z;

    We can find the closure F+of F, by repeated application of rules IR-1 to

    IR-3. These rules are called asArmstrongs Inference rules.

    Inference Rules for FDs

    6 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    8/29BITS Pilani, Hyderabad Campus7 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    9/29BITS Pilani, Hyderabad Campus

    Normalizationprocess is first proposed by

    Raymond Boyce and Edgar Coddin 1972.

    Normalization of data is the process of analyzing relation

    schemas based on their FDs and PKs/Keys to achieve thedesirable properties of

    (i)Minimal redundancy

    (ii)Minimal anomalies

    Normalization & Normal forms

    8 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    10/29BITS Pilani, Hyderabad Campus

    DId Dname Dloc

    10 Engg HYD

    CHENNAI

    20 Mark HYD

    MUMBAI

    1. First Normal Form (INF)

    It states that the domain of any attribute must include only

    atomic (single / simple/ individual) values.

    In the example given below, under the column Dloceach

    row has more than on values.

    Ex.: Dept

    9 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    11/29BITS Pilani, Hyderabad Campus

    2. Second Normal Form (2NF)It is based on full functional dependency.

    {X A} is fully functional if we remove any attribute from X then

    that FD does not hold anymore.

    Condition for 2NF: All non-key attributes are fully functionally dependent onkey (or) no non-key attribute should be dependent on part of key(partial

    dependency).

    eid pnum Hours ename ploc

    10 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    12/29BITS Pilani, Hyderabad Campus11 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    13/29BITS Pilani, Hyderabad Campus

    Here, {ename} is a non key attribute anddetermined by {eid}which is part of the key. Hence

    we say that enamenot fully functionally dependent

    on key.

    The relation shown is not in 2NF. Now we candecompose this in to three relations as shown

    below.

    eid ename pnum ploc eid pnum hours

    12 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    14/29BITS Pilani, Hyderabad Campus13 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    15/29BITS Pilani, Hyderabad Campus

    3. Third Normal form (3NF)

    It is based on transitive dependency.

    According to this, a relation should not have a non key attribute

    functionally determined by another non key attribute. i.e., there should

    be no transitive dependency.

    eid addressename dnum dname dloc

    Not in 3NF, because Dnameis transitively dependent on eid.

    14 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    16/29BITS Pilani, Hyderabad Campus

    Now we can decompose the above into 2 relations.

    eid addressename dnum Dnum Dname dloc

    Condition for 3NF

    For each FD, X A in database

    i) X must be a superkey or

    ii) A is key attribute

    15 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    17/29

  • 8/14/2019 SS ZG518-L7.ppt

    18/29BITS Pilani, Hyderabad Campus17 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    19/29BITS Pilani, Hyderabad Campus18 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    20/29BITS Pilani, Hyderabad Campus19 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    21/29BITS Pilani, Hyderabad Campus20 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    22/29BITS Pilani, Hyderabad Campus

    As we have seen, decomposition (of a bigger relation R

    into smaller ones), is a major step in the process of

    normalization.

    But during this activity of decomposition, we need tomake sure that the decomposition is losslessand

    dependency preserving

    Decomposition and Desirable properties

    21 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    23/29

    BITS Pilani, Hyderabad Campus

    1

    ( )R

    r r 2 ( )R r

    1

    ( )R

    r

    Let C represent a set of constraints on the database. A decomposition{R1, R2, R3,.R4} of a relation schema R is a lossless join

    decomposition for R if all relation instances ron R that are legal under

    C.

    .= r

    = projection of ron R1

    rrelation instance in R

    F = FDs on R

    (or) {R} {R1, R2}

    *

    Loss-less join Decomposition

    22 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    24/29

    BITS Pilani, Hyderabad Campus23 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    25/29

    BITS Pilani, Hyderabad Campus

    Test for Lossless join property

    24 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    26/29

    BITS Pilani, Hyderabad Campus25 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    27/29

    BITS Pilani, Hyderabad Campus

    Given a set of dependencies F on R, the projection of F on Ri

    denoted by

    (where Riis a subset of R); is the set of FDs X Y in F+such that the

    attributes in X Y are contained in Ri.

    1 2( ) ( ) ...., ( )

    mR R R

    F F F F

    Then it is dependency preserving decomposition.

    - is projection of F on R1.1 ( )R f

    Dependency Preserving Decomposition

    26 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    28/29

    BITS Pilani, Hyderabad Campus27 27/08/2013 SSZG 518 Database Design & Applications Dr.R.Gururaj

  • 8/14/2019 SS ZG518-L7.ppt

    29/29

    Summary

    Introduction to Database Design

    Functional Dependencies and Inference Rules

    Concepts in Normalization

    Normal Forms (1NF,2NF,3 NF and BCNF)

    Desirable properties of Decomposition

    (requirements)

    Lossless join decomposition and tests

    Dependency preserving decomposition and tests