9-DB-Normalization

download 9-DB-Normalization

of 61

Transcript of 9-DB-Normalization

  • 8/7/2019 9-DB-Normalization

    1/61

    In the name ofALLAH

  • 8/7/2019 9-DB-Normalization

    2/61

    Introduction toDatabase Systems

    Lecture 22

    03-01-11

    Fall 2010

  • 8/7/2019 9-DB-Normalization

    3/61

    Department of Computer Science

    Normalization

    A step by step process to

    produce more efficient and

    accurate database design

    Purpose is to produce ananomaly free design

  • 8/7/2019 9-DB-Normalization

    4/61

    Department of Computer Science

    Anomalies

    A state ofDB that can lead the DB

    to inconsistency or incorrect state of

    database

    Four types of anomalies are of

    concern here; Redundancy,

    insertion, deletion and updation

  • 8/7/2019 9-DB-Normalization

    5/61

    Department of Computer Science

    Normalization

    A strongly recommended step

    Normalized design makes the

    maintenance of database easier

    Normalization applied on each

    table of a DB design

  • 8/7/2019 9-DB-Normalization

    6/61

    Department of Computer Science

    Normalization

    Performed after the logical

    database design

    Informally also performed

    during conceptual DB design

  • 8/7/2019 9-DB-Normalization

    7/61

    Department of Computer Science

    Normalization Process

    Different forms or levels of normalization

    Called first, second, third and so on

    forms

    Each form has got certain conditions

    If a table fulfils the condition(s) for a

    normal form then the table is in that

    normal form

  • 8/7/2019 9-DB-Normalization

    8/61

    Department of Computer Science

    Normalized DB Design

    Process is applied on each table

    The minimum form in which all tables

    are in is called the normal form of the

    entire database Objective is to place the DB in

    highest form of normalization

  • 8/7/2019 9-DB-Normalization

    9/61

    Department of Computer Science

    Functional Dependency

    Normalization is based on

    functional dependencies (FDs)

    A type of relationship between

    attributes of a relation

  • 8/7/2019 9-DB-Normalization

    10/61

    Department of Computer Science

    Functional Dependency

    Definition: IfA and B are attributes

    of a relation R, then B isfunctionally dependent on A if each

    value ofA in R is associated with

    exactly one value ofB; written as

    A B

  • 8/7/2019 9-DB-Normalization

    11/61

    Department of Computer Science

    Functionally Dependency

    It does not mean that A derives B,

    although it may be the case sometime Means that if we know value ofA then

    we can precisely determine a unique

    value ofB

  • 8/7/2019 9-DB-Normalization

    12/61

    Department of Computer Science

    Functional Dependency

    Attribute of set of attributes on the left

    side are called determinant and on theright are called dependents

    Like R (a, b, c, d, e)

    a b, c, d

    d d, e

  • 8/7/2019 9-DB-Normalization

    13/61

    Department of Computer Science

    FD Example

    STD(stId, stName, stAdr, prName, credits)

    stId stName, stAdr, prName, credits

    prName credits

  • 8/7/2019 9-DB-Normalization

    14/61

  • 8/7/2019 9-DB-Normalization

    15/61

    In the name ofALLAH

  • 8/7/2019 9-DB-Normalization

    16/61

    Introduction toDatabase Systems

    Lecture 23

    06-01-11

    Fall 2010

  • 8/7/2019 9-DB-Normalization

    17/61

  • 8/7/2019 9-DB-Normalization

    18/61

    Department of Computer Science

    FDs and Keys

    A minimal super key is the

    candidate key, so if adeterminant of an FD determines

    all attributes of that relation then

    it is definitely a super key, and

  • 8/7/2019 9-DB-Normalization

    19/61

    Department of Computer Science

    FDs and Keys

    If there is no other FD where a subset of

    this determinant/SK is a super key, thenit is a candidate key

    So FDs help to identify keys, how

  • 8/7/2019 9-DB-Normalization

    20/61

    Department of Computer Science

    R(a, b, c, d, e, f, g)

    a, c b, d, e, f, g

    c d, e

    a b, d, ff g, a, b, c, d, e

  • 8/7/2019 9-DB-Normalization

    21/61

    Department of Computer Science

    FDs and Keys

    EMP(eId, eName, eAdr, eDept, prId, prSal)

    eId eName, eDept, eAdr

    eId, prId prSalSTD(stId, stName, prName, adr, nic, cgpa)

    stId stName, prName, adr, nic, cgpa

    nic stName, prName, adr, stId, cgpa

  • 8/7/2019 9-DB-Normalization

    22/61

    Department of Computer Science

    Inference Rules

    Called inference axioms or armstrong

    axioms These are rules that establish certain

    FDs from a given set of FDs

    These rules are sound

  • 8/7/2019 9-DB-Normalization

    23/61

    Department of Computer Science

    Reflexivity

    IfB is a subset ofA then A B,

    it also implies that A A

    always hold, that is

    stName, stAdr stName

    Or stName stName

  • 8/7/2019 9-DB-Normalization

    24/61

    Department of Computer Science

    Augmentation

    If we have A B then

    AC BC that is

    if stId stName then

    stId, stA

    drstName, st

    Adr

  • 8/7/2019 9-DB-Normalization

    25/61

    Department of Computer Science

    Transitivity

    IfA B and BC then

    A C

    that is

    If stId

    prName and prNamecredits

    Then stId credits

  • 8/7/2019 9-DB-Normalization

    26/61

    Department of Computer Science

    Additivity or Union

    IfA B and A C then ABC

    if empId eName and empId qual

    Then we can write it as

    empId

    eName, qual

  • 8/7/2019 9-DB-Normalization

    27/61

    Department of Computer Science

    Projectivity or Decomposition

    IfA BC then A B and ACif empId eName, qual

    Then we can write it as

    empId eName and empId qual

  • 8/7/2019 9-DB-Normalization

    28/61

    Department of Computer Science

    Pseudotransitivity

    IfA B and CB D then

    AC Dif stId stName and

    stName, fName stAdr

    Then we can write it as

    stId, fName stAdr

  • 8/7/2019 9-DB-Normalization

    29/61

    Department of Computer Science

    Thanks

  • 8/7/2019 9-DB-Normalization

    30/61

    In the name ofALLAH

  • 8/7/2019 9-DB-Normalization

    31/61

    Introduction toDatabase Systems

    Lecture 24

    10-01-11

    Fall 2010

  • 8/7/2019 9-DB-Normalization

    32/61

    Normal Forms

  • 8/7/2019 9-DB-Normalization

    33/61

    Department of Computer Science

    First Normal Form

    A relation is in first normal form

    iff every attribute in every tuple

    contains an atomic value

    There is no multivaued(repeating group) in the relation

  • 8/7/2019 9-DB-Normalization

    34/61

    Department of Computer Science

    First Normal Form

    One of the basic properties of relation

    Multiple values create problems inperforming different operations, like, select

    or join

    Remember the treatment of multivalued

    attributes in the mapping process

  • 8/7/2019 9-DB-Normalization

    35/61

  • 8/7/2019 9-DB-Normalization

    36/61

    Department of Computer Science

    First Normal FormstId bkId stName stAdr prName

    S1020 B00129 Sohail Dar I-8 Islamabad MCS

    S1038 B00327 ShoaibAli G-6 Islamabad BCS

    S1015 B08945 Tahira Ejaz L RukhWah MCS

    S1015 B06352 Tahira Ejaz L RukhWah MCS

    S1018 B08474 Arif Zia E-8, Islamabad. BIT

    Mind the key please

  • 8/7/2019 9-DB-Normalization

    37/61

    Department of Computer Science

    Second Normal Form

    Full functional dependency: an

    attribute B is fully functionallydependent on A if the B can be

    determined by whole ofA not by

    any proper subset ofA

  • 8/7/2019 9-DB-Normalization

    38/61

    Department of Computer Science

    Full Functional Dependence

    Consider the relation

    CLASS(crId, stId, stName, fId, room, grade)

    crId, stId stName, fId, room, grade

    stId stName

    crId fId, room

  • 8/7/2019 9-DB-Normalization

    39/61

    Department of Computer Science

    Second Normal Form

    A relation is in 2nd normal form iff it

    is in the first normal form and allnon key attributes are fully

    functionally dependent on key,

    that is, there is no partialdependency

  • 8/7/2019 9-DB-Normalization

    40/61

    Department of Computer Science

    Anomalies

    crId stId stName fId room grade

    C3456 S1020 Suhail Dar F2345 104 B

    C5678 S1020 Suhail Dar F4567 106

    C3456 S1038 M Shoaib F2345 104

  • 8/7/2019 9-DB-Normalization

    41/61

    Department of Computer Science

    Second Normal Form

    CLASS(crId, stId, stName, fId, room, grade)

    crId, stId stName, fId, room, grade

    stId

    stName crId

    fId, room

  • 8/7/2019 9-DB-Normalization

    42/61

    Department of Computer Science

    Anomalies

    Redundancy

    Insertion Anomaly

    Deletion Anomaly

    UpdationA

    omaly

  • 8/7/2019 9-DB-Normalization

    43/61

    Department of Computer Science

    Anomalies

    crId stId stName fId room grade

    C3456 S1020 Suhail Dar F2345 104 B

    C5678 S1020 Suhail Dar F4567 106

    C3456 S1038 Shoaib Ali F2345 104 A

    C5678 S1015 Tahira Ejaz F4567 106 B

  • 8/7/2019 9-DB-Normalization

    44/61

    Department of Computer Science

    Second Normal Form

    Relation is decomposed based on the FDsCLASS(crId, stId, stName, fId, room, grade)

    crId, stId stName, fId, room, grade

    stId stName crId fId, room

    STD(stId, stName)

    COURSE(crId, fId, room)

    CLASS(crId, stId, grade)

  • 8/7/2019 9-DB-Normalization

    45/61

    Department of Computer Science

    Second Normal Form

    Each of these tables is insecond normal form

    Free of anomalies due to partial

    dependency

  • 8/7/2019 9-DB-Normalization

    46/61

    Department of Computer Science

    Thanks

  • 8/7/2019 9-DB-Normalization

    47/61

  • 8/7/2019 9-DB-Normalization

    48/61

    Introduction toDatabase Systems

    Lecture 25

    03-01-11

    Fall 2010

  • 8/7/2019 9-DB-Normalization

    49/61

    Department of Computer Science

    Third Normal Form

    A table is in third normal form

    (3NF) iff it is in 2NF and there isno transitive dependency, that

    is, no non-key attribute is

    dependent on another non-keyattribute

  • 8/7/2019 9-DB-Normalization

    50/61

    Department of Computer Science

    Transitive Dependency

    STD(stId, stName, stAdr, prName, prCrdts)

    stId stName, stAdr, prName, prCrdtsprName prCrdts

  • 8/7/2019 9-DB-Normalization

    51/61

  • 8/7/2019 9-DB-Normalization

    52/61

    Department of Computer Science

    stId stName stAdr prName

    S1020 Sohail Dar I-8 Islamabad MCS

    S1038 ShoaibAli G-6 Islamabad BCS

    S1015 Tahira Ejaz L RukhWah MCS

    S1018 Arif Zia E-8, Islamabad. BIT

  • 8/7/2019 9-DB-Normalization

    53/61

    Department of Computer Science

    prName prCrdts

    MCS 68

    BCS 132

    BIT 134

  • 8/7/2019 9-DB-Normalization

    54/61

    Department of Computer Science

    Third Normal Form

    STD(stId, stName, stAdr, prName, prCrdts)

    stId stName, stAdr, prName, prCrdts prName prCrdts

    STD (stId, stName, stAdr, prName)

    PROGRA

    M (prName, prCrdts)

  • 8/7/2019 9-DB-Normalization

    55/61

    Department of Computer Science

    3NF Relations

    Each of the table is in 3NF Free of all anomalies

  • 8/7/2019 9-DB-Normalization

    56/61

    Department of Computer Science

    Boyce-Codd Normal Form

    A general form of 3NF

    Every relation in BCNF is in 3NFvice-versa is not always true

    3NF is checked in steps, BCNF

    checked directly

  • 8/7/2019 9-DB-Normalization

    57/61

    Department of Computer Science

    BCNF

    A table is in BCNF if every

    determinant is a candidate key

    Situation when table in 3NF is

    not in BCNF

    A non-key determines a part of

    the composite primary key

  • 8/7/2019 9-DB-Normalization

    58/61

    Department of Computer Science

    BCNF

    FACULTY(fId, dept, office, rank, dateHired)

    fId, dept office, rank, dateHiredoffice dept

    Table is in 3NF, not in BCNF since the office is not a

    candidate key

    Generates multiple overlapping candidate keys so wehave fId, office dept, rank, dateHired

  • 8/7/2019 9-DB-Normalization

    59/61

    Department of Computer Science

    BCNF

    We decompose the table again to

    bring it into BCNFFACULTY (fId, dept, office, rank, dateHired)

    FACULTY(fId, office, rank, dateHred)

    OFFICE(office, dept)

  • 8/7/2019 9-DB-Normalization

    60/61

    Department of Computer Science

    HigherNormal Forms

    AfterBCNF fourth, fifth and domain-

    key normal forms exist 4NF deals with multivalued

    dependency, fifth deals with possible

    lossless decompositions,D

    KNFreduces further chances of any

    possible inconsistency

  • 8/7/2019 9-DB-Normalization

    61/61

    Consistent hardwork is major

    key for success in life