©niit normalizing and denormalizing data lesson 2b / slide 1 of 18 objectives in this section, you...

18
Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 ©NIIT Normalizing and Denormalizing Data Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach Describe data redundancy Describe the first, second, and third normal forms Describe the Boyce-Codd Normal Form (BCNF) Appreciate the need for denormalization

Upload: bruce-logan

Post on 13-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18©NIIT

Normalizing and Denormalizing Data

Objectives

In this section, you will learn to:

• Describe the Top-down and Bottom-up approach

• Describe data redundancy

• Describe the first, second, and third normal forms

• Describe the Boyce-Codd Normal Form (BCNF)

• Appreciate the need for denormalization

Page 2: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 2 of 18©NIIT

Normalizing and Denormalizing Data

Pre-assessment Questions1. The scenario where a student can do only one project and no other student can do

the same project, the relationship between student and project is a ______ relationship.a. One-to-Oneb. One-to-Manyc. Many-to-Oned. Many-to-Many

2. Which of the following options is true?a. The primary key of the supertype is the primary key of the subtype.b. The foreign key of the supertype is the primary key of the subtype.c. The primary key of the supertype is the foreign key of the subtype.d. The foreign key of the supertype is the foreign key of the subtype.

Page 3: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 3 of 18©NIIT

Normalizing and Denormalizing Data

Pre-assessment Questions (Contd..)3. A candidate key that does not become a primary key is called a(n) ______ key.

a. Candidate keyb. Foreign keyc. Alternate keyd. Composite key

4. Which of the following problems arise when a primary key is allowed NULL values?a. It becomes difficult to identify the rows uniquely.b. It becomes difficult to identify the columns uniquely.c. It becomes difficult to join tables.d. It becomes difficult to identify foreign key.

5. In ______, every higher-level entity must also be a lower-level entity.a. Generalizationb. E/R diagramc. Specializationd. Many-to-Many relationship

Page 4: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 4 of 18©NIIT

Normalizing and Denormalizing Data

Solutions

Ans1. One-to-One

Ans2. The primary key of the supertype is the foreign key of the subtype.

Ans3. Alternate key

Ans4. It becomes difficult to identify the rows uniquely.

Ans5. Generalization

Page 5: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 5 of 18©NIIT

Normalizing and Denormalizing Data

Top-Down and Bottom-Up Approach • There are two approaches to logical database design:

• The top-down approach

• The bottom-up approach

• The E/R modeling technique is the top-down approach. It involves identifying entities, relationships and attributes, drawing the E/R diagram, and mapping the diagram to tables.

• Normalization is the bottom-up approach. It is a step-by-step decomposition of complex records into simple records.

• Normalization reduces redundancy using the principle of non-loss decomposition.

• Non-loss decomposition is the reduction of a table to smaller tables without any loss of information.

• The bottom-up approach is best for validation of existing designs.

Page 6: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 6 of 18©NIIT

Normalizing and Denormalizing Data

Data Redundancy• Redundancy means repetition of data.

• Redundancy increases the time involved in updating, adding, and deleting data.

• Redundancy also increases the utilization of disk space, and hence, disk I/O increases.

• Redundancy can lead to:

• Update anomalies—Inserting, modifying, and deleting data may cause inconsistencies.

• Inconsistencies—Errors are more likely to occur when facts are repeated.

• Unnecessary utilization of extra disk space.

Page 7: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 7 of 18©NIIT

Normalizing and Denormalizing Data

Need for Normalization• Normalization is a scientific method of breaking down complex

table structures into simple table structures by using certain rules.

• Using normalization, you can reduce redundancy in a table and eliminate the problems of inconsistency and disk space usage.

• You can also ensure that there is no loss of information.

• Normalization has several benefits as follows:

• It enables faster sorting and index creation.

• It helps to create more clustered indexes.

• It requires few indexes per table.

• It reduces the number of NULL values in a table.

• It makes the database compact.

Page 8: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 8 of 18©NIIT

Normalizing and Denormalizing Data

Need for Normalization (Contd..)• The performance of an application is directly linked to the

database design.

• Some rules that should be followed to achieve a good database design are:

• Each table should have an identifier.

• Each table should store data for a single type of entity.

• Columns that accept NULLs should be avoided.

• The repetition of values or columns should be avoided.

Page 9: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 9 of 18©NIIT

Normalizing and Denormalizing Data

Normal Forms• Normalization results in the formation of tables that satisfy certain

specified rules and represent certain normal forms.

• The normal forms are used to ensure that various types of anomalies and inconsistencies are not introduced in the database.

• A table structure is always in a certain normal form.

• The most important and widely used normal forms are:

• First Normal Form (1NF)

• Second Normal Form (2 NF)

• Third Normal Form (3 NF)

• Boyce-Codd Normal Form (BCNF)

Page 10: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 10 of 18©NIIT

Normalizing and Denormalizing Data

Functional Dependency• The normalization theory is based on the fundamental notion of

functional dependency.

• In a relation R, attribute A is functionally dependent on attribute B if each value of A in R is associated with precisely one value of B.

• Attribute B is called the determinant.

• All attributes of a table must be functionally dependent on the key. However, functional dependency does not require an attribute to be the key in order to functionally determine other attributes.

• Functional dependency can also be defined as follows:Given a relation R, attribute A is functionally dependent on B onlyif whenever two tuples of R agree on their B value, they mustagree on their A value.

• Functional dependencies represent many-to-one relationships.

Page 11: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 11 of 18©NIIT

Normalizing and Denormalizing Data

First Normal Form (1 NF)

• A table is said to be in the 1 NF when each cell of the table contains precisely one value.

Page 12: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 12 of 18©NIIT

Normalizing and Denormalizing Data

Second Normal Form (2 NF)

• A table is said to be in 2 NF when it is in 1 NF and every attribute in the row is functionally dependent upon the whole key, and not just part of the key.

• Guidelines for converting a table to 2 NF:

• Find and remove attributes that are functionally dependent on only a part of the key and not on the whole key. Place them in a different table.

• Group the remaining attributes.

Page 13: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 13 of 18©NIIT

Normalizing and Denormalizing Data

Third Normal Form (3 NF)

• A table is said to be in the 3 NF when it is in 2 NF and every non-key attribute is functionally dependent only on the primary key.

• Guidelines for converting a table to 3 NF:

• Find and remove non-key attributes that are functionally dependent on attributes that are not the primary key. Place them in a different table.

• Group the remaining attributes.

Page 14: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 14 of 18©NIIT

Normalizing and Denormalizing Data

Boyce-Codd Normal Form (BCNF)

• The original definition of 3 NF was inadequate and not satisfactory for the tables:

• that had multiple candidate keys.

• where the multiple candidate keys were composite.

• where the multiple candidate keys overlapped.

• The Boyce-Codd Normal Form (BCNF) was introduced to normalize the table in the above conditions.

• A relation is in BCNF if and only if every determinant is a candidate key.

• Guidelines for converting a table to BCNF:

• Find and remove the overlapping candidate keys. Place the part of the candidate key and the attribute it is functionally dependent on, in a different table.

• Group the remaining items into a table.

Page 15: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 15 of 18©NIIT

Normalizing and Denormalizing Data

Denormalization • The intentional introduction of redundancy in a table in order to

improve query performance is called denormalization.

• The decision to denormalize results in a trade-off between performance and data consistency.

• Denormalization also increases disk space utilization.

Page 16: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 16 of 18©NIIT

Normalizing and Denormalizing Data

SummaryIn this lesson, you learned that:

• There are two approaches to logical database design:

• The top-down approach

• The bottom-up approach

• The E/R modeling technique is the top-down approach, while normalization is the bottom-up approach.

• Normalization is used to simplify table structures.

• Normalization results in the formation of tables that satisfy certain specified constraints, and represent certain normal forms.

• A table structure is always in a certain normal form.

Page 17: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 17 of 18©NIIT

Normalizing and Denormalizing Data

Summary (Contd..)

• The most important and widely used normal forms are:

• First Normal Form (1 NF)

• Second Normal Form (2 NF)

• Third Normal Form (3 NF)

• Boyce-Codd Normal Form (BCNF)

• The normalization theory is based on the fundamental notion of functional dependency. Functional dependencies represent many-to-one relationships.

• A table is said to be in the 1 NF when each cell of the table contains precisely one value.

• A table is said to be in the 2NF when it is in 1 NF and every attribute in the row is functionally dependent upon the whole key, and not just part of the key.

• A table is said to be in the 3NF when it is in 2 NF and every non-key attribute is functionally dependent only on the primary key.

Page 18: ©NIIT Normalizing and Denormalizing Data Lesson 2B / Slide 1 of 18 Objectives In this section, you will learn to: Describe the Top-down and Bottom-up approach

Normalizing and Denormalizing Data Lesson 2B / Slide 18 of 18©NIIT

Normalizing and Denormalizing Data

Summary (Contd..)

• The original definition of 3NF was inadequate and not satisfactory for the tables:

• that had multiple candidate keys.

• where the multiple candidate keys were composite.

• where the multiple candidate keys overlapped.

• A relation is in the Boyce-Codd normal form (BCNF) if and only if every determinant is a candidate key.

• The intentional introduction of redundancy in a table in order to improve query performance is called denormalization.

• The decision to denormalize results in a trade-off between performance and data consistency.

• Denormalization also increases disk space utilization.