29
Rules of Database Normalization 06/13/22 1

Rules of Database Normalization

Embed Size (px)

DESCRIPTION

Rules of Database Normalization. Overview. What is Normalization ? What is the objective of Normalization ? Why is Normalization in a database important? What are NORMAL FORMS ? How do we accomplish Normalization in our database? Are there times when Normalization is unnecessary?. - PowerPoint PPT Presentation

Citation preview

Page 1: Rules of Database Normalization

Rules of DatabaseNormalization

04/19/231

Page 2: Rules of Database Normalization

What is Normalization? What is the objective of Normalization? Why is Normalization in a database

important? What are NORMAL FORMS? How do we accomplish Normalization in our

database? Are there times when Normalization is

unnecessary?

04/19/232

Overview

Page 3: Rules of Database Normalization

Normalization refers to the process of creating an efficient, reliable, flexible, and appropriate “relational” structure for storing information in a “relational” data structure.

Normalization usually involves dividing a database into two or more tables and defining the relationship between the tables.

04/19/233

What is Normalization?

Page 4: Rules of Database Normalization

The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships.

04/19/234

What is the objective of Normalization?

Page 5: Rules of Database Normalization

Normalization removes redundant data from your tables in order to improve storage efficiency.

Normalization removes redundant data and improves data integrity.

Normalization removes redundant data and helps in maintenance problems. Example: If data that exists in more than one place must be changed, the data must be changed in exactly the same way in all locations.

Finally, Normalization removes redundant data and improves the scalability of your database.

04/19/235

Why is Normalization in a database important?

Page 6: Rules of Database Normalization

A series of logical steps to normalize data tables. First Normal Form-1NF Second Normal Form-2NF Third Normal Form-3NF Fourth Normal Form-4NF Fifth Normal Form-5NF• We will learn the First, Second and Third

Normal Forms

04/19/236

What are NORMAL FORMS?

Page 7: Rules of Database Normalization

The definition of the first Normal Form is as follows

There are no repeating groups.All of the key attributes are defined.All attributes are dependent on the primary

key.Example on the next slide.

04/19/237

What is the First Normal Form?

Page 8: Rules of Database Normalization

How do we accomplish First Normal Form? Look at this example.

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName-1

Rate Category-1

Hourly Rate-1

EmployeeName 2

Rate Category

Hourly Rate

1023, 1056

MadagascarTravel site andOnlineEstate Agency

11 Julius Wilson A $60 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

8

Page 9: Rules of Database Normalization

Notice the repeating Groups.

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName-1

Rate Category-1

Hourly Rate-1

EmployeeName 2

Rate Category

Hourly Rate

1023, 1056

MadagascarTravel site andOnlineEstate Agency

11 Julius Wilson A $60 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056Online Estate Agency

17 Charles Saul D $30

04/19/23

9

Page 10: Rules of Database Normalization

This is our solution to eliminating the repeating groups

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

10

Page 11: Rules of Database Normalization

How can we set our Primary Key?

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

11

Page 12: Rules of Database Normalization

Can this be our Primary Key?

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

12

Page 13: Rules of Database Normalization

Or, can this be our Primary Key?

ProjectNumber

ProjectName

EmployeeNumber

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

13

Page 14: Rules of Database Normalization

Solution-We need both as our Primary Keys.

ProjectNumberPrimary Key

ProjectName

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

14

Page 15: Rules of Database Normalization

Is our table in First Normal Form?

ProjectNumberPrimary Key

ProjectName

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascarTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $60

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

15

Page 16: Rules of Database Normalization

A table is in 2nd Normal Form if:1) It is in 1st normal form.2) It includes no partial dependencies (where

an attribute is dependent on only a part of a primary key).

04/19/2316

What is Second Normal Form

Page 17: Rules of Database Normalization

Does it include partial dependencies? Do you notice anything else?

ProjectNumberPrimary Key

ProjectName

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascatTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $50

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

17

Page 18: Rules of Database Normalization

Look at “Project Name” Row 3. Also look at Hourly Rate? What about

data integrity?ProjectNumberPrimary Key

ProjectName

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

1023 MadagascarTravel site

11 Julius Wilson A $60

1023 MadagascarTravel site

12 Monica Jefferson

B $50

1023 MadagascatTravel site

16 Daniel Moore C $40

1056 Online Estate Agency

11 Julius Wilson A $50

1056 Online Estate Agency

17 Charles Saul D $30

04/19/23

18

Page 19: Rules of Database Normalization

Step One:ProjectName

EmployeeNumber

1023 11

1023 12

1023 16

1056 11

1056 17

04/19/23

19

Project Name is only Dependent on Project Number; so, we create a“Employee Project Table.”

Employee-Project Table

Page 20: Rules of Database Normalization

Step Two:

ProjectNumberPrimary Key

ProjectName

1023 MadagascarTravel site

1056 Online Estate Agency

04/19/23

20

Notice that “Project Name” is dependent on only“Project Number.”We create our “Project Table” With Project Number as our Primary Key. Look at the space we have saved. What else have we done?

Project Table

Page 21: Rules of Database Normalization

Step Three:

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

11 Julius Wilson A $60

12 Monica Jefferson

B $50

16 Daniel Moore C $40

17 Charles Saul D $30

04/19/23

21

Notice that Employee Name, Rate Category, and Hourly Rate are dependent onEmployee Number.We create our “Employee Table” withEmployee Number as our Primary Key.

Employee Table

Page 22: Rules of Database Normalization

Are we now in Second Normal Form?

ProjectNamePrimary Key

EmployeeNumber Primary Key

1023 11

1023 12

1023 16

1056 11

1056 17

04/19/23

22

Project Table Employee TableEmployee Project Table

Is it in First Normal Form and does it includes no partial Dependencies?

ProjectNumberPrimary Key

ProjectName

1023 MadagascarTravel site

1056 Online Estate Agency

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

11 Julius Wilson A $60

12 Monica Jefferson B $50

16 Daniel Moore C $40

17 Charles Saul D $30

Project Table

ProjectNamePrimary Key

EmployeeNumber Primary Key

1023 11

1023 12

1023 16

1056 11

1056 17

Employee Project Table

Page 23: Rules of Database Normalization

It is in SECOND Normal Form. It contains no transitive dependencies

(where a non-key attribute is dependent on another non-key attribute).

Let’s see where we begin.

04/19/2323

Now, What is Third Normal Form?

Page 24: Rules of Database Normalization

Let’s take another look at what we have.?

ProjectNamePrimary Key

EmployeeNumber Primary Key

1023 11

1023 12

1023 16

1056 11

1056 17

04/19/23

24

Project Table Employee TableEmployee Project Table

ProjectNumberPrimary Key

ProjectName

1023 MadagascarTravel site

1056 Online Estate Agency

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

11 Julius Wilson A $60

12 Monica Jefferson B $50

16 Daniel Moore C $40

17 Charles Saul D $30

Project TableEmployee Project Table

Page 25: Rules of Database Normalization

Can we do anything else with this table?

04/19/2325

Let’s look at the Employee Project Table

ProjectNamePrimary Key

EmployeeNumber Primary Key

1023 11

1023 12

1023 16

1056 11

1056 17

Employee Project Table

Page 26: Rules of Database Normalization

Let’s Look at the Project Table.

ProjectNumberPrimary Key

ProjectName

1023 MadagascarTravel site

1056

Online Estate Agency

04/19/23

26

Can we do anything else with this table?

Project Table

Page 27: Rules of Database Normalization

Can we further normalize this table?

04/19/2327

Let’s look at the Employee table

Employee Table

EmployeeNumberPrimary Key

EmployeeName

Rate Category

Hourly Rate

11 Julius Wilson A $60

12 Monica Jefferson B $50

16 Daniel Moore C $40

17 Charles Saul D $30

Page 28: Rules of Database Normalization

See what we can do with the employee table.

Let’s make an “Rate” Table

Rate CategoryPrimary Key

Hourly Rate

A $60

B $50

C $40

D $30

04/19/23

28

Employee Table

EmployeeNumberPrimary Key

EmployeeName

Rate Category

11 Julius Wilson A

12 Monica Jefferson B

16 Daniel Moore C

17 Charles Saul D

Rate Table

We have now reduced the possibility of Employees being paidIncorrectly. Our database Will have more integrity.

Page 29: Rules of Database Normalization

That’s It!

Our data is now in 3NF.. Ready to be used in a DBMS…

04/19/23

29