Explain normalization in SQL Server

Normalization is the process of organizing data into a related table; it also eliminates redundancy and increases the integrity which improves performance of the query. Database normalization can essentially be defined as the practice of optimizing table structures. Optimization is accomplished as a result of a thorough investigation of the various pieces of data that will be stored within the database, in particular concentrating upon how this data is interrelated.

Normalization avoids:
  • Avoids Duplicates - it makes sure that duplicate data is not stored
  • Insert Anomaly - A record about an entity cannot be inserted into the table without first inserting information about another entity - Cannot enter a customer without a sales order
  • Update Anomaly - Cannot update information without changing information in many places. To update customer information, it must be updated for each sales order the customer has placed
  • Delete Anomaly - A record cannot be deleted without deleting a record about a related entity. Cannot delete a sales order without deleting all of the customer's information
De-normalization is a process whereby redundant columns are added to the table to speed up the execution time and complicity of using joins.

Example Table
Items Colors Price Tax
Pen Red, Blue 20 0.20
Scale Green, Orange 30 0.30

Normalization stages:
  • First Normal Form - 1 NF
    Items Colors Price Tax
    Pen Red 20 0.20
    Pen Blue 20 0.20
    Scale Green 30 0.30
    Scale Orange 30 0.30
    • The table cell should be of single value
    • Duplicate data should be removed
    • Each row should be identified by a primary key

  • Second Normal Form - 2 NF
    Items Colors
    Pen Red
    Pen Blue
    Scale Green
    Scale Orange

    Items Price Tax
    Pen 20 0.20
    Scale 30 0.30
    • Removes partial dependencies
    • Functional Dependency - the value of one attribute is determined entirely by another attribute
    • Partial Dependency - the value of one attribute is partially dependent on a primary key
    • Create a separate table with the functional dependent data and the partial section of the primary key
  • Third Normal Form - 3 NF
    Items Colors
    Pen Red
    Pen Blue
    Scale Green
    Scale Orange

    Items Price
    Pen 20
    Scale 30

    Price Tax
    20 0.20
    30 0.30
    • Removes transitive dependencies
    • Transitive Dependency - whereby an attribute is dependent on another attribute other than the primary key

  • Boyce-Codd Normal Form - BCNF
  • Fourth Normal Form - 4 NF
  • Fifth Normal Form - 5 NF

Comments

Popular posts from this blog

jQuery Basics

What is the difference between a Page Layout and Master Page in SharePoint?

Accessing data from SharePoint 2010 to an ASP.NET application