normal (all forms+er diag)

Upload: anubhav-gupta

Post on 03-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Normal (All forms+ER diag)

    1/40

    Chapter 5Normalization of Database Tables

  • 8/12/2019 Normal (All forms+ER diag)

    2/40

    Database Tables and

    Normalization

    Normalizationis a process for assigning attributes toentities. It reduces data redundancies and helps eliminate

    the data anomalies.

    Normalization works through a series of stages callednormal forms:

    First normal form (1NF)

    Second normal form (2NF)

    Third normal form (3NF)

    Fourth normal form (4NF)

    The highest level of normalization is not always desirable.

  • 8/12/2019 Normal (All forms+ER diag)

    3/40

    Database Tables and Normalization

    The Need for Normalization

    Case of a Construction Company

    Building project -- Project number, Name, Employeesassigned to the project.

    Employee -- Employee number, Name, Job classification

    The company charges its clients by billing the hours spenton each project. The hourly billing rate is dependent onthe employees position.

    Periodically, a report is generated.

    The table whose contents correspond to the reportingrequirements is shown in Table 5.1.

  • 8/12/2019 Normal (All forms+ER diag)

    4/40

    Scenario

    A few employees works forone project.

    Project Num : 15

    Project Name :Evergreen

    Employee Num :101, 102, 103,105

  • 8/12/2019 Normal (All forms+ER diag)

    5/40

    Sample Form

    Project Num : 15

    Project Name : Evergreen

    Emp Num Emp Name Job Class Chr Hours Hrs Billed Total

    101102

    103

    105

  • 8/12/2019 Normal (All forms+ER diag)

    6/40

  • 8/12/2019 Normal (All forms+ER diag)

    7/40

    Table Structure Matches

    the Report Format

  • 8/12/2019 Normal (All forms+ER diag)

    8/40

    Problems with the Figure 5.1

    The project number is intended to be a primary key, but it

    contains nulls.

    The table displays data redundancies.

    The table entries invite data inconsistencies.

    The data redundancies yield the following anomalies:

    Update anomalies.

    Addition anomalies.

    Deletion anomalies.

    Database Tables and Normalization

  • 8/12/2019 Normal (All forms+ER diag)

    9/40

    Conversion to First Normal Form

    A relational table must not contain repeating groups.

    Repeating groups can be eliminated by adding theappropriate entry in at least the primary keycolumn(s).

    Database Tables and Normalization

  • 8/12/2019 Normal (All forms+ER diag)

    10/40

    Data Organization: First Normal Form

    Before

    After

  • 8/12/2019 Normal (All forms+ER diag)

    11/40

    1NF Definition

    The term first normal form (1NF) describes thetabular format in which:

    All the key attributes are defined.

    There are no repeating groups in the table.

    All attributes are dependent on the primary key.

    First Normal Form (1 NF)

  • 8/12/2019 Normal (All forms+ER diag)

    12/40

    Dependency Diagram

    The primary key components are bold, underlined, and shaded ina different color.

    The arrows above entities indicate all desirable dependencies,i.e., dependencies that are based on PK.

    The arrows below the dependency diagram indicate lessdesirable dependencies -- partial dependencies andtransitivedependencies.

    Dependency Diagram

  • 8/12/2019 Normal (All forms+ER diag)

    13/40

    Conversion to Second Normal Form

    Starting with the 1NF format, the database can be converted

    into the 2NF format by Writing each key component on a separate line, and then

    writing the original key on the last line and

    Writing the dependent attributes after each new key.

    PROJECT (PROJ_NUM, PROJ_NAME)EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS, CHG_HOUR)

    ASSIGN (PROJ_NUM,EMP_NUM, HOURS)

    Second Normal Form (2 NF)

  • 8/12/2019 Normal (All forms+ER diag)

    14/40

    Dependency Diagram

  • 8/12/2019 Normal (All forms+ER diag)

    15/40

    A table is in 2NF if:

    It is in 1NF and

    It includes no partial dependencies; that is, noattribute is dependent on only a portion of theprimary key.

    (It is still possible for a table in 2NF to exhibittransitive dependency; that is, one or moreattributes may be functionally dependent onnonkey attributes.)

    Second Normal Form (2 NF)

  • 8/12/2019 Normal (All forms+ER diag)

    16/40

    Conversion to Third Normal Form

    Create a separate table with attributes in a transitivefunctional dependence relationship.

    PROJECT (PROJ_NUM, PROJ_NAME)

    ASSIGN (PROJ_NUM, EMP_NUM, HOURS)

    EMPLOYEE (EMP_NUM, EMP_NAME, JOB_CLASS)

    JOB (JOB_CLASS, CHG_HOUR)

    Third Normal Form (3 NF)

  • 8/12/2019 Normal (All forms+ER diag)

    17/40

    3NF Definition

    A table is in 3NF if:

    It is in 2NF and

    It contains no transitive dependencies.

    Third Normal Form (3 NF)

  • 8/12/2019 Normal (All forms+ER diag)

    18/40

    The Completed

    Database

  • 8/12/2019 Normal (All forms+ER diag)

    19/40

    A table is in Boyce-Codd normal form(BCNF) if everydeterminant in the table is a candidate key.

    (A determinant is any attribute whose valuedetermines other values with a row.)

    If a table contains only one candidate key, the 3NF andthe BCNF are equivalent.

    BCNF is a special case of 3NF. Figure 5.7 illustrates a table that is in 3NF but not in

    BCNF.

    Figure 5.8 shows how the table can be decomposed toconform to the BCNF form.

    Boyce-Codd Normal Form (BCNF)

  • 8/12/2019 Normal (All forms+ER diag)

    20/40

    A Table That Is In 3NF

    But Not In BCNF

  • 8/12/2019 Normal (All forms+ER diag)

    21/40

    The Decomposition of a Table Structure

    to Meet BCNF Requirements

  • 8/12/2019 Normal (All forms+ER diag)

    22/40

    Sample Data for a BCNF Conversion

  • 8/12/2019 Normal (All forms+ER diag)

    23/40

    Decomposition into BCNF

  • 8/12/2019 Normal (All forms+ER diag)

    24/40

    BCNF Definition

    A table is in BCNF if every determinant in that tableis a candidate key. If a table contains only onecandidate key, 3NF and BCNF are equivalent.

    BCNFDefinition

  • 8/12/2019 Normal (All forms+ER diag)

    25/40

    Normalization will help us identify correct and

    appropriate TABLES. Until Now we have 4tables

    Normalization

    PROJECT(PROJ_NUM, PROJ_NAME)

    ASSIGN(PROJ_NUM, EMP_NUM, HOURS)

    EMPLOYEE(EMP_NUM, EMP_NAME, JOB_CLASS)

    JOB(JOB_CLASS, CHG_HOUR)

  • 8/12/2019 Normal (All forms+ER diag)

    26/40

    We are going to identify the relationships

    between entities (tables) including theircardinality, connectivity.

    We have to list out the Business Rules.

    NEXT ........

    PROJECT(PROJ_NUM, PROJ_NAME)

    ASSIGN(PROJ_NUM, EMP_NUM, HOURS)

    EMPLOYEE(EMP_NUM, EMP_NAME, JOB_CLASS)

    JOB(JOB_CLASS, CHG_HOUR)

  • 8/12/2019 Normal (All forms+ER diag)

    27/40

    Business Rules

    The company manages many projects.

    Each project requires the services of many employees.

    An employee may be assigned to several differentprojects.

    Some employees are not assigned to a project andperform duties not specifically related to a project.Some employees are part of a labor pool, to be shared

    by all project teams. Each employee has a (single) primary job

    classification. This job classification determines thehourly billing rate.

    Many employees can have the same job classification.

  • 8/12/2019 Normal (All forms+ER diag)

    28/40

    Two Initial Entities:

    PROJECT (PROJ_NUM, PROJ_NAME)

    EMPLOYEE (EMP_NUM, EMP_LNAME, EMP_FNAME,EMP_INITIAL, JOB_DESCRIPTION, JOB_CHG_HOUR)

    Normalization and Database Design

  • 8/12/2019 Normal (All forms+ER diag)

    29/40

    Three Entities After Transitive Dependency Removed

    PROJECT (PROJ_NUM, PROJ_NAME)

    EMPLOYEE (EMP_NUM, EMP_LNAME, EMP_FNAME, EMP_INITIAL,JOB_CODE)

    JOB (JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HOUR)

    Normalization and Database Design

  • 8/12/2019 Normal (All forms+ER diag)

    30/40

    The Modified ERD

  • 8/12/2019 Normal (All forms+ER diag)

    31/40

    Creation of Composite Entity ASSIGN

  • 8/12/2019 Normal (All forms+ER diag)

    32/40

    Attribute ASSIGN_HOUR is assigned to the composite entityASSIGN.

    Manages relationship is created between EMPLOYEE andPROJECT.

    PROJECT(PROJ_NUM, PROJ_NAME, EMP_NUM)

    EMPLOYEE(EMP_NUM, EMP_LNAME, EMP_FNAME, EMP_INITIAL,

    EMP_HIREDATE, JOB_CODE)

    JOB(JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HOUR)

    ASSIGN(ASSIGN_NUM, ASSIGN_DATE, PROJ_NUM, EMP_NUM,

    ASSIGN_HOURS)

    Normalization and Database Design

  • 8/12/2019 Normal (All forms+ER diag)

    33/40

    Relational Schema

  • 8/12/2019 Normal (All forms+ER diag)

    34/40

    Higher-Level Normal Forms

    4NF Definition

    A table is in 4NF if it is in 3NF and has no multiple sets

    of multivalued dependencies.

  • 8/12/2019 Normal (All forms+ER diag)

    35/40

    A Set of Tables in 4NF

  • 8/12/2019 Normal (All forms+ER diag)

    36/40

    Denormalization

    Normalizationis only one of many database design

    goals. Normalized(decomposed) tables require additional

    processing, reducing system speed.

    Normalization purity is often difficult to sustain in

    the modern database environment. The conflictbetween design efficiency, informationrequirements, and processing speed are oftenresolved through compromises that includedenormalization.

  • 8/12/2019 Normal (All forms+ER diag)

    37/40

    SUMMARY

  • 8/12/2019 Normal (All forms+ER diag)

    38/40

    The Initial 1NF Structure

  • 8/12/2019 Normal (All forms+ER diag)

    39/40

    Identifying the Possible PK Attributes

  • 8/12/2019 Normal (All forms+ER diag)

    40/40

    Table Structures Based On

    The Selected PKs