Вы находитесь на странице: 1из 23

Data Base Normalization

And
Entity Relationship Diagrams

10/6/15

Normalization

10/6/15

Database normalization is the process of


removing redundant data from your tables in to
improve storage efficiency, data integrity, and
scalability.
Normalization generally involves splitting existing
tables into multiple ones, which must be re-joined
or linked each time a query is issued.
Edgar F. Codd originally established three normal
forms: 1NF, 2NF and 3NF. There are now others
that are generally accepted, but 3NF is widely
considered to be sufficient for most applications.
Most tables when reaching 3NF are also in BCNF
(Boyce-Codd Normal Form).
2

1 Normal Form
st

Rules of First Normal Form


1. Create separate tables for each group
of related data and ensure each row is
unique by identifying a primary key .
2. Eliminate duplicate columns from the
same table.
**Primary key : A primary key is either a single field or combined set of
fields that uniquely identify a single row of data in a table

10/6/15

1st Normal Form Example

Let say we want to build a database


that can manage Books.
We can create an entity(table) like
this
Entity

Book
Title

Author1
Author2
Fields

ISBN
Subject
Pages
Publisher

10/6/15

Title
Database
System
Concepts
Operating
System

Author1

Author2 ISBN

Subject

Pag Publish
es
er

Abraham Henry F. 7295 MySQL, 11 McGra


Silberschatz Korth 8863 Computers 68 w-Hill
4716
4
Abraham Henry F. 9466
94 McGra

1 Normal Form
st

In our Table 1, we have two violations


of First Normal Form:
First, we have more than one author
field,
Second, our subject field contains
more than one piece of information.
With more than one value in a single
field, it would be very difficult to
search for all books on a given
subject.
10/6/15

1st Normal Form


Before Normalization
Title
Author1
Database System
Abraham
Concepts
Silberschatz
Operating System
Abraham
Concepts
Silberschatz

Author2
ISBN
Henry F. 729588
Korth
63
Henry F. 471694
Korth
665

Subject
MySQL,
Computers

Pages

Computers

944

1168

Publisher
McGrawHill
McGrawHill

1st Normal Form


Title
Author
Database System
Abraham
Concepts
Silberschatz
Database System
Concepts
Henry F. Korth
Operating System
Concepts
Henry F. Korth
Operating System
Abraham
Concepts
We now
have twoSilberschatz
rows for a

ISBN

Subject

Pages

72958863 MySQL
1168
Comput
72958863
ers
1168
47169466 Comput
5
ers
944
47169466 Comput
5 book.
ersAdditionally,
944
single

Publisher
McGrawHill
McGrawHill
McGrawHill
McGrawwe Hill

would be violating the Second Normal Form.


A better solution to our problem would be to separate the data
into separate tables- an Author table and a Subject table to
store our information, removing that information from the Book
table:
10/6/15

1st Normal Form


1stNormal Form
Subjects Table

Authors Table

Subject_ID

Subject

Author_I
D

MySQL

Computers

First
Last Name
Name
Abraha
Silberschatz
m
Korth

Henry

Books Table
ISBN
72958863
471694665
10/6/15

Pag
Title
es Publisher
Database System 116 McGrawConcepts
8
Hill
Operating System
McGrawConcepts
944
Hill
7

nd

Normal Form

Meet all the requirements of 1st


Normal Form.
Remove redundant data and place
them in separate tables
Create relationships between tables
through the use of foreign keys.
Foreign Key : The foreign key create the foundation of a relationship
between two tables by inserting the primary key from one table
into another table
10/6/15

nd

Normal Form

Publisher Table
Publisher_ID

Publisher Name

McGraw-Hill
Books Table

ISBN

Page Publisher_I
s
D

Title
Database System
72958863
Concepts
1168
1
Here we have a one-to-many relationship between the book table
Operating System
and the publisher. A book has only one publisher, and a publisher
471694665
Concepts
944
1
will publish many books. When we have a one-to-many
relationship, we place a foreign key in the Book Table, pointing to
the primary key of the Publisher Table.

10/6/15

3 Normal Form
rd

Meet all the requirements of 2nd


Normal Form
Remove all attributes from a table
that are not directly dependant on
primary key .

10/6/15

10

Entity Relationship
Diagrams

10/6/15

11

Entity and Attribute


An entity is a business object that
represents a group, or category of
data.
An attribute is a sub-group of
information within an entity.
Entity Table
Attribute Column
10/6/15

12

Entity Relationship Models

Mandatory Relationships
Optional Relationships
Many-to-Many Relationships
One-to-Many Relationships
One-to-One Relationships
Recursive Relationships

10/6/15

13

Mandatory, Many-to-Many

10/6/15

INSTRUCTOR

STUDENT

INSTRUCTOR

STUDENT

14

Optional, Many-to-Many

10/6/15

DEPARTMENT

STUDENT

DEPARTMENT

STUDENT

15

Optional/Mandatory,
Many-to-Many

10/6/15

INSTRUCTOR

SKILL

INSTRUCTOR

SKILL

16

Optional/Mandatory,
One-to-Many

10/6/15

PRODUCT

VENDOR

PRODUCT

VENDOR

17

Mandatory, One-to-One

10/6/15

AUTOMOBILE

ENGINE

AUTOMOBILE

ENGINE

18

Recursive
EMPLOYEE

supervises

is supervised by

10/6/15

19

Resolving Many-to-Many
Relationships
Many-to-many relationships should
be avoided. We can resolve a manyto-many relationship by dividing it
into two one-to-many relationships.

10/6/15

20

Resolving Many-to-Many
Relationships

SALES ORDERS

SALES ORDERS

10/6/15

INV. ITEMS

ORDER ITEMS

INV. ITEMS

21

Example (ER Diagram)


CUSTOMERS

CLERKS

SALES ORDERS

ORDER ITEMS

10/6/15

INV. ITEMS

22

HR Schema ER Diagram

Вам также может понравиться