Anda di halaman 1dari 20

Oracle 11g: SQL

Chapter 1 Overview of Database Concepts: Normalization

Objectives
Normalization process First normal form (1NF) Second normal form (2NF) Third normal form (3NF)

Oracle 11g: SQL

Data Redundancy
Data redundancy refers to having the same
data in different places within a database

Data anomalies refers to data


inconsistencies

Data redundancy may lead to data


inconsistency that results in incorrect data

Oracle 11g: SQL

Process for evaluating and correcting table


structures to reduce data anomalies
Minimizes data redundancies Reduces data inconsistency

Database Normalization

Works through a series of stages called normal


forms:
First normal form (1NF) Second normal form (2NF) Third normal form (3NF)

Often 2NF is better than 1NF; 3NF is better than 2NF


but the higher the level the slower the database response Most relational tables are in 3NF
Oracle 11g: SQL

Normalization Process
Progressively breaks a table into a new set of
tables (relations) based on identified dependencies

Each table represents a single subject No data item will be unnecessarily stored in more
than one table

All attributes in a table are dependent on the


primary key

Each table void of insertion, update, deletion


Oracle 11g: SQL

anomalies
5

Unnormalized Data: Example


Contains repeating groups in the AUTHOR
column in the BOOKS table
Groups of multiple entries of the same type that
exist for any single key attribute occurrence

Oracle 11g: SQL

First-Normal Form (1NF)


Table is in 1NF if:
Primary key (PK) is identified Repeating groups are eliminated

Conversion to 1NF:
Eliminate repeating groups Identify PK Identify dependencies
Oracle 11g: SQL

First-Normal Form: Example


ISBN and AUTHOR columns together create
a composite primary key

Oracle 11g: SQL

Composite Primary Key


More than one column is required to
uniquely identify a row

Can lead to partial dependency a


column is only dependent on a portion of the primary key Example: TITLE depends on ISBN only

Oracle 11g: SQL

Second-Normal Form (2NF)


Table is in 2NF if: Its in 1NF It contains no partial dependencies Conversion to 2NF:

If PK is composite, break it into two parts and use


each key attribute as PK in a new table

Move dependent attributes to the new tables Create a bridge between the two tables with the
original composite PK and attributes that dependent on it 10 Oracle 11g: SQL

2NF: Special Case


Since partial dependencies can exist only if
there is a composite key, a table with a simple PK (single attribute; not composite) is automatically in 2NF if it is in 1NF

Oracle 11g: SQL

11

Second-Normal Form: Example


When BOOKS converted to 2NF:
ISBN becomes PK in BOOKS AUTHOR becomes PK in a new table
AUTHOR column is not the best choice for PK
(numerical values are preferred) but it will be changed as normalization continues

Oracle 11g: SQL

12

Second-Normal Form: Example


Since there is a M:N relationship between
BOOKS and AUTHOR, a bridge is needed Once BOOKS converted to 2NF and the
AUTHOR table is created, add a bridge table BOOKAUTHOR and link it with two 1:M relationships with BOOKS and AUTHOR

Oracle 11g: SQL

13

Third-Normal Form (3NF)


Table is in 3NF if:
Its in 2NF It contains no transitive dependencies

Conversion to 3NF:
For each transitive dependency, use the
determinant as PK in a new table but keep it within the original table Move dependent attributes to the new table
Oracle 11g: SQL

14

Third-Normal Form: Example


When BOOKS converted to 3NF: PUBLISHER and CONTACT are used to
create a new PUBLISHER table CONTACT is removed from BOOKS

Oracle 11g: SQL

15

Dependency Diagram
To show the primary key and all the dependencies, you
can use a dependency diagram Dependencies between PK and other attributes are depicted
above the diagram Partial or transitive dependencies are depicted below the diagram and identified (for instance, PD, TD)

Dependency diagram for the AUTHOR table in 3NF:

Oracle 11g: SQL

16

Dependency Diagram in Visio


To create a dependency diagram in Visio, select the
General template category, then Block Diagram

For attributes, use one of the rectangular shapes


available in the Shapes section

Use the Connector tool to connect attributes on the


diagram

To change attributes color, select all the attributes,


right-click, click Format, select Fill, and choose the color you want
Oracle 11g: SQL 17

Improving the Design


Normalization does not to produce a perfect normalized set
of tables

Once normalization is complete, go over the result to make


sure possible issues are addressed: Evaluate PK Assignments Double-check if all tables are linked Evaluate Naming Conventions Refine Attribute Atomicity Identify New Attributes Identify New Relationships Refine Primary Keys as Required for Data Granularity
Oracle 11g: SQL 18

Improving the Design: Example


Once the BOOKS table is normalized, the newly created PUBLISHER
table includes two attributes:

PUBLISHER, CONTACT
None of these attributes is a good choice for PK:
Add a new attribute PUB_ID and use it as PK Re-visit the BOOKS table and change the name of the foreign key column
(PUBLISHER) to PUB_ID to be consistent with the PUBLISHER table

You can also include additional attributes or re-name existing ones to


better describe the PUBLISHER entity: NAME, PHONE, ADDRESS, etc.

Final version of PUBLISHER: PUB_ID, NAME, CONTACT, PHONE


Oracle 11g: SQL 19

Summary
Normalization is the process for evaluating and
correcting table structures to reduce data redundancies

1NF:
Eliminate repeating groups Identify the primary key

2NF:
Table is in 1NF Partial dependencies are eliminated

3NF:
Table is in 2NF Transitive dependencies are eliminated
Oracle 11g: SQL

20

Anda mungkin juga menyukai