28
Normalization I Normalization I

Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Normalization INormalization I

Page 2: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

ObjectivesObjectivesPurpose of normalization.Purpose of normalization.

Problems associated with redundant data.Problems associated with redundant data.

Identification of various types of update Identification of various types of update anomalies such as insertion, deletion, and anomalies such as insertion, deletion, and modification anomalies.modification anomalies.

How to recognize appropriateness or How to recognize appropriateness or quality of the design of relations.quality of the design of relations.

Page 3: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

ObjectivesObjectives

How functional dependencies can be used to How functional dependencies can be used to group attributes into relations that are in a group attributes into relations that are in a known normal form.known normal form.

How to undertake process of normalization.How to undertake process of normalization.

How to identify most commonly used How to identify most commonly used normal forms, namely 1NF, 2NF, 3NF, normal forms, namely 1NF, 2NF, 3NF, and and Boyce–Codd normal form (BCNF).Boyce–Codd normal form (BCNF).

How to identify fourth (4NF) and fifth (5NF) How to identify fourth (4NF) and fifth (5NF) normal forms.normal forms.

Page 4: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

NormalizationNormalization

Main objective in developing a logical Main objective in developing a logical data model for relational database data model for relational database systems is to create an accurate systems is to create an accurate representation of the data, its representation of the data, its relationships, and constraints.relationships, and constraints.

To achieve this objective, must identify a To achieve this objective, must identify a suitable set of relations.suitable set of relations.

Page 5: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

NormalizationNormalizationFour most commonly used normal forms Four most commonly used normal forms are first (1NF), second (2NF) and third are first (1NF), second (2NF) and third (3NF) normal forms, (3NF) normal forms, and Boyce–Codd and Boyce–Codd normal form (BCNF).normal form (BCNF).

Based on functional dependencies among Based on functional dependencies among the attributes of a relation.the attributes of a relation.

A relation can be normalized to a specific A relation can be normalized to a specific form to prevent possible occurrence of form to prevent possible occurrence of update anomalies.update anomalies.

Page 6: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Data RedundancyData Redundancy

Major aim of relational database design Major aim of relational database design is to group attributes into relations to is to group attributes into relations to minimize data redundancy and reduce minimize data redundancy and reduce file storage space required by base file storage space required by base relations.relations.

Problems associated with data Problems associated with data redundancy are illustrated by comparing redundancy are illustrated by comparing the following Staff and Branch relations the following Staff and Branch relations with the StaffBranch relation.with the StaffBranch relation.

Page 7: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Data RedundancyData Redundancy

Page 8: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Data RedundancyData Redundancy

StaffBranch relation has redundant data: StaffBranch relation has redundant data: details of a branch are repeated for every details of a branch are repeated for every member of staff.member of staff.

In contrast, branch information appears only In contrast, branch information appears only once for each branch in Branch relation and once for each branch in Branch relation and only branchNo is repeated in Staff relation, to only branchNo is repeated in Staff relation, to represent where each member of staff works.represent where each member of staff works.

Page 9: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Update AnomaliesUpdate Anomalies

Relations that contain redundant Relations that contain redundant information may potentially suffer from information may potentially suffer from update anomalies. update anomalies.

Types of update anomalies include:Types of update anomalies include: InsertionInsertion DeletionDeletion Modification.Modification.

Page 10: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Lossless-join and Dependency Lossless-join and Dependency Preservation PropertiesPreservation Properties

Two important properties of decomposition:Two important properties of decomposition:

- Lossless-join property- Lossless-join property enables us to find any enables us to find any instance of original relation from instance of original relation from corresponding instances in the smaller corresponding instances in the smaller relations. relations.

- Dependency preservation property- Dependency preservation property enables us enables us to enforce a constraint on original relation by to enforce a constraint on original relation by enforcing some constraint on each of the enforcing some constraint on each of the

smaller relations.smaller relations.

Page 11: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency

Main concept associated with Main concept associated with normalization.normalization.

Functional DependencyFunctional Dependency Describes relationship between attributes in a Describes relationship between attributes in a

relation. relation. If A and B are attributes of relation R, B is If A and B are attributes of relation R, B is

functionally dependent on A (denotedfunctionally dependent on A (denoted A A B B), ), if each value of A in R is associated with exactly if each value of A in R is associated with exactly one value of B in R.one value of B in R.

Page 12: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency

Property of the meaning (or semantics) Property of the meaning (or semantics) of the attributes in a relation.of the attributes in a relation.

Diagrammatic representation:Diagrammatic representation:

Determinant of a functional dependency refers to attribute or group of attributes on left-hand side of the arrow.

Page 13: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Example - Functional Example - Functional DependencyDependency

Page 14: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency

Main characteristics of functional Main characteristics of functional dependencies used in normalization:dependencies used in normalization:

have a 1:1 relationship between attribute(s) have a 1:1 relationship between attribute(s) on left and right-hand side of a dependency;on left and right-hand side of a dependency;

hold for all time;hold for all time; are nontrivial.are nontrivial.

Page 15: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency Complete set of functional dependencies Complete set of functional dependencies for a given relation can be very large. for a given relation can be very large.

ImportantImportant to find an approach that can to find an approach that can reduce set to a manageable size.reduce set to a manageable size.

Need toNeed to identify set of functional identify set of functional dependencies (X) for a relation that is dependencies (X) for a relation that is smaller than complete set of functional smaller than complete set of functional dependencies (Y) for that relation and has dependencies (Y) for that relation and has property that every functional property that every functional dependency in Y is implied by functional dependency in Y is implied by functional dependencies in X. dependencies in X.

Page 16: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency

Set of all functional dependencies implied Set of all functional dependencies implied by a given set of functional dependencies by a given set of functional dependencies X called closure of X (written XX called closure of X (written X++).).

Set of inference rules, called Armstrong’s Set of inference rules, called Armstrong’s axioms, specifies how new functional axioms, specifies how new functional dependencies can be inferred from given dependencies can be inferred from given ones.ones.

Page 17: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Functional DependencyFunctional Dependency

Let A, B, and C be subsets of the attributes of Let A, B, and C be subsets of the attributes of relation R. Armstrong’s axioms are as follows:relation R. Armstrong’s axioms are as follows:

  1. Reflexivity1. Reflexivity

If B is a subset of A, then If B is a subset of A, then AA BB2. Augmentation2. Augmentation

If If AA B, B, thenthen A,C A,C CC3. Transitivity3. Transitivity

If If AA B B andand B B C, C, thenthen A A CC

Page 18: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

The Process of The Process of NormalizationNormalization

Formal technique for analyzing a relation Formal technique for analyzing a relation based on its primary key and functional based on its primary key and functional dependencies between its attributes.dependencies between its attributes.

Often executed as a series of steps. Each Often executed as a series of steps. Each step corresponds to a specific normal form, step corresponds to a specific normal form, which has known properties.which has known properties.

As normalization proceeds, relations As normalization proceeds, relations become progressively more restricted become progressively more restricted (stronger) in format and also less (stronger) in format and also less vulnerable to update anomalies.vulnerable to update anomalies.

Page 19: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Relationship Between Relationship Between Normal FormsNormal Forms

Page 20: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Unnormalized Form Unnormalized Form (UNF)(UNF)

A table that contains one or more A table that contains one or more repeating groups.repeating groups.

To create an unnormalized To create an unnormalized table: table: transform data from information source transform data from information source

(e.g. form) into table format with (e.g. form) into table format with columns and rows.columns and rows.

Page 21: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

First Normal Form (1NF)First Normal Form (1NF)A relation in which intersection of A relation in which intersection of each row and column contains one each row and column contains one and only one value.and only one value.

Page 22: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

UNF to 1NFUNF to 1NFNominate an attribute or group of Nominate an attribute or group of attributes to act as the key for the attributes to act as the key for the unnormalized table.unnormalized table.

Identify repeating group(s) in Identify repeating group(s) in unnormalized table which repeats for unnormalized table which repeats for the key attribute(s).the key attribute(s).

Page 23: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

UNF to 1NFUNF to 1NF

Remove repeating group by:Remove repeating group by: entering appropriate data into the entering appropriate data into the

empty columns of rows containing empty columns of rows containing repeating data (‘flattening’ the table).repeating data (‘flattening’ the table).

Or byOr by placing repeating data along with copy placing repeating data along with copy

of the original key attribute(s) into a of the original key attribute(s) into a separate relation.separate relation.

Page 24: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Second Normal Form Second Normal Form (2NF)(2NF)

Based on concept of full functional Based on concept of full functional dependency:dependency: A and B are attributes of a relation, A and B are attributes of a relation, B is fully dependent on A if B is functionally B is fully dependent on A if B is functionally

dependent on A but not on any proper subset dependent on A but not on any proper subset of A.of A.

2NF - A relation that is in 1NF and every 2NF - A relation that is in 1NF and every non-primary-key attribute is fully non-primary-key attribute is fully functionally dependent on the primary key.functionally dependent on the primary key.

Page 25: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

1NF to 2NF1NF to 2NFIdentify primary key for the 1NF Identify primary key for the 1NF relation.relation.

Identify functional dependencies in the Identify functional dependencies in the relation.relation.

If partial dependencies exist on the If partial dependencies exist on the primary key remove them by placing primary key remove them by placing them in a new relation along with copy them in a new relation along with copy of their determinant.of their determinant.

Page 26: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

Third Normal Form (3NF)Third Normal Form (3NF)Based on concept of transitive Based on concept of transitive dependency:dependency: A, B and C are attributes of a relation such A, B and C are attributes of a relation such

that if A that if A B and B B and B C, C, then C is transitively dependent on A through then C is transitively dependent on A through

B. (Provided that A is not functionally B. (Provided that A is not functionally dependent on B or C).dependent on B or C).

3NF - A relation that is in 1NF and 2NF and in 3NF - A relation that is in 1NF and 2NF and in which no non-primary-key attribute is which no non-primary-key attribute is transitively dependent on the primary key.transitively dependent on the primary key.

Page 27: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

2NF to 3NF2NF to 3NFIdentify the primary key in the 2NF Identify the primary key in the 2NF relation.relation.

Identify functional dependencies in the Identify functional dependencies in the relation.relation.

If transitive dependencies exist on the If transitive dependencies exist on the primary key remove them by placing primary key remove them by placing them in a new relation along with copy them in a new relation along with copy of their determinant.of their determinant.

Page 28: Normalization I. Objectives Purpose of normalization. Problems associated with redundant data. Identification of various types of update anomalies such

General Definitions of 2NF and General Definitions of 2NF and 3NF3NF

Second normal form (2NF)Second normal form (2NF) A relation that is in 1NF and every non-A relation that is in 1NF and every non-

primary-key attribute is fully functionally primary-key attribute is fully functionally dependent on dependent on anyany candidate keycandidate key..

Third normal form (3NF)Third normal form (3NF) A relation that is in 1NF and 2NF and in A relation that is in 1NF and 2NF and in

which no non-primary-key attribute is which no non-primary-key attribute is transitively dependent on transitively dependent on any candidate keyany candidate key..