Top Banner

of 16

Database Tables and Normalization

May 30, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/14/2019 Database Tables and Normalization

    1/16

    1

    Database Tables and NormalizationDatabase Tables and NormalizationNormalization is a process for assigning

    attributes to entities. It reduces dataredundancies.

    Normalization works through a series of stagescalled normal forms:First Normal Form (1NF)Second Normal Form (2NF)Third Normal Form (3NF) etc..

    The highest level of normalization is not alwaysdesirable.

  • 8/14/2019 Database Tables and Normalization

    2/16

    2

    Guidelines for Designing Relations

    Guideline 1: Design relations so that the the meaning ofthe data is clear. Do not combine attributes from different

    entities and relationships into a single relation.

    Guideline 2: Design relations so that no insertion, deletion

    or modification PROBLEMS are likely to occur.

    Guideline 3: As far as possible, avoid including attributes

    in a relation that have null values in a majority of the tuples.

    Guideline 4: Design relations that can be JOINed with

    each other using equality conditions on attributes that are

    either primary keys or foreign keys.

  • 8/14/2019 Database Tables and Normalization

    3/16

    3

    Keys The role of the key is based on a concept known as

    determination, which is used in the definition offunctional

    dependence.

    An attribute B is functionally dependenton an attribute

    A if the value of A determines the value of B.

    An attribute that is part of a primary or candidate key isknown as a key( orprime) attribute. Else, it is a non-

    key(ornon-prime) attribute.

    If an attribute B is functionally dependent on a composite

    key A but not on any subset of A, then B is fully

    functionally dependenton A; otherwise B ispartially

    dependenton A.

  • 8/14/2019 Database Tables and Normalization

    4/16

    4

    Two Other Dependencies

    Partial Dependency

    A functional dependency A determines B is apartial

    dependencyif the dependency holds even after removing

    some attribute from A.

    Transitive Dependency

    A transitive dependencyoccurs when one non-prime attribute

    depends on another non-prime attribute.

  • 8/14/2019 Database Tables and Normalization

    5/16

    5

    1NF Definition

    The term First Normal Form (1NF) describes the

    tabular format in which:

    All the prime attributes are defined and have

    non-null values.

    All table entries are atomic, i.e., no cell of the

    table contains a group of items.All attributes are dependent on the primary key.

    Database Tables and NormalizationDatabase Tables and Normalization

  • 8/14/2019 Database Tables and Normalization

    6/16

    6

    Customer

    Customer ID First Name Surname Tel. No. 1 Tel. No. 2 Tel. No. 3

    123 Robert Ingram 2025456

    124 Jane Wright 555-403-1 659555-776-

    Customer

    Customer ID First Name Surname

    1 Robert Ingram

    2 Jane Wright

    Customer Telephone Number

    Customer ID Telephone Number

    1 2025456

    2 555-403-1

    124 659555-776-

  • 8/14/2019 Database Tables and Normalization

    7/16

    7

    2NF DefinitionA table is in Second Normal Form (2NF) if:

    It is in 1NF, and

    It includes no partial dependencies, i.e., no

    attribute is dependent on only a part of a

    composite candidate key.

    Note that it is possible for a table in 2NF toexhibit transitive dependency, i.e., a non-prime

    attribute can be functionally dependent on some

    other non-prime attribute.

    Database Tables and NormalizationDatabase Tables and Normalization

  • 8/14/2019 Database Tables and Normalization

    8/16

    8

    Consider a table describing employees' skills:

    Employee Skill Current Work Location

    Jones Typing 114 Main Street

    Jones Shorthand 114 Main Street

    Jones Whittling 114 Main Street

    Roberts Light Cleaning 73 Industrial Way

    The table's only candidate key is {Employee, Skill}.The remaining

    attribute, Current Work Location, is dependent on only part of the

    candidate key, namely Employee. Therefore the table is not in 2NF.

    Note the redundancy in the way Current Work Locations are

    represented: we are told three times that Jones works at 114 Main

    Street. This redundancy makes the table prone to update problems.

  • 8/14/2019 Database Tables and Normalization

    9/16

    9

    A 2NF alternative to this design would represent the same informationin two tables:

    Employees

    Employee Current Work Location

    Jones 114 Main Street

    Roberts 73 Industrial Way

    Employees' SkillsEmployee Skill

    Jones Typing

    Jones Shorthand

    Jones WhittlingRoberts Light Cleaning

  • 8/14/2019 Database Tables and Normalization

    10/16

    10

    3NF DefinitionA table is in Third Normal Form (3NF) if:

    It is in 2NF, and

    It contains no transitive dependencies.

    Database Tables and NormalizationDatabase Tables and Normalization

  • 8/14/2019 Database Tables and Normalization

    11/16

    11

  • 8/14/2019 Database Tables and Normalization

    12/16

    12

    To normalize data to achieve third normal

    form-

    Identify and remove any attribute which is

    actually dependent on a non-key attribute

    in the same relation .

    Create a new relation for this attribute

    identified by the relevant key.

  • 8/14/2019 Database Tables and Normalization

    13/16

    13

  • 8/14/2019 Database Tables and Normalization

    14/16

    14

    DenormalizationDenormalization

    Normalization is only one of many database designgoals.

    Normalized (decomposed) tables require additional

    processing.

    Normalization purity is often difficult to sustain in

    the modern database environment. The conflict

    between design efficiency, information require-ments, and processing speed are often resolved

    through compromises that include denormalization.

  • 8/14/2019 Database Tables and Normalization

    15/16

    15

    Merging Relations (View Integration)

    This is required when, on large projects, the

    work of several sub-teams comes together

    during logical design.

    Problems that may arise:

    Synonyms: Different names, same

    meaning.

    Homonyms: Same name, different

    meanings.

  • 8/14/2019 Database Tables and Normalization

    16/16

    16

    SynonymsSTUDENT1 (Student_ID, Name)

    STUDENT2 (SSN, Name, Address)

    If Student_ID is same as SSN, the two relations can be merged to

    STUDENT (SSN, Name, Address)

    HomonymsSTUDENT1 (Student_ID, Name, Address)

    STUDENT2 (Student_ID, Name, Phone, Address)

    If one address refers to the campus address and the other to the home

    address, the relations can be merged to

    STUDENT (Student_ID, Name, Phone, Campus_addr, Home_addr)