16
Database Normalization Lynne Weldon July 17, 2000

Database Normalization Lynne Weldon July 17, 2000

Embed Size (px)

Citation preview

Page 1: Database Normalization Lynne Weldon July 17, 2000

Database Normalization

Lynne Weldon

July 17, 2000

Page 2: Database Normalization Lynne Weldon July 17, 2000

2

Database Basics

• Collection of related information organized as

– Tables

• Information about a particular physical or conceptual object

– Examples: instructors, courses, books, students

– Records, represented as rows

• Information about a particular instance of the object

– Examples: 1 instructor, 1 course, 1 book, 1 student

– Fields, represented as columns

• Particular piece of information about the objects in the

database

– Examples: instructor's last name, course number, book title, student's SSN

Page 3: Database Normalization Lynne Weldon July 17, 2000

3

Employee Database Table without Primary Key

• The Employee Table is comprised of

– 8 Records (1 per employee), each containing

• 5 Fields

– Last Name, First Name, Dept Code, Dept Name, Dept Bldg

• Problem - No field to uniquely identify a record

Page 4: Database Normalization Lynne Weldon July 17, 2000

4

Employee Database Table with Primary Key

• A Primary Key is one or more fields which uniquely identify a record

• The Employee ID field is the Primary Key for the Employee Table

• If you know an employee's ID, you will always be able to

locate the record for that employee

Page 5: Database Normalization Lynne Weldon July 17, 2000

5

Why Normalize Data?

• Save typing of redundant data which will

reduce the effect of data entry errors

• Save storage space

• Avoid frequent restructuring of tables and

other objects to accommodate new data

• Increase flexibility to query, sort, summarize,

and group data

To have the most efficiently designed tables

Page 6: Database Normalization Lynne Weldon July 17, 2000

6

What is Normalization?

• Organizing data to minimize redundancy

• Successive steps followed to identify and eliminate poor

table definition

• Each step is referred to as a "Form"

– 1st Normal Form (1NF)– 2nd Normal Form (2NF)– 3rd Normal Form (3NF)– 4th Normal Form (4NF)– 5th Normal Form (5NF)

• Database designers agree that 3NF is sufficient for most

databases

Page 7: Database Normalization Lynne Weldon July 17, 2000

7

Expected Outcome as Normalization Proceeds

• Absence of fields containing no data

• More database tables

• Less fields in each of the new database tables

• Elimination of non-key redundant data

Page 8: Database Normalization Lynne Weldon July 17, 2000

8

Unnormalized Database Table

• What has to be done if an employee is assigned a fourth project?

• Notice the blank fields

• There are repeating fields to store project information for each employee

• Each time a new employee is added, the complete department information (3 fields) must be entered

• How many records must be changed if the name of a department or a building changes? (Example: Technical Writing)

• Notice the redundant data

Page 9: Database Normalization Lynne Weldon July 17, 2000

9

Establishing First Normal Form

• Eliminate repeating groups of fields.

• Problems in the Employee Table

– Repeating fields are used for each project an employee is

assigned to

• Project Number

• Time Spent on Project

Page 10: Database Normalization Lynne Weldon July 17, 2000

10

First Normal Form Established

• The table does not contain repeating groups of fields.

• There is one Project Number field and one Time Spent on Project field.

• Separate records were created for additional projects an employee is assigned.

Page 11: Database Normalization Lynne Weldon July 17, 2000

11

Establishing Second Normal Form

• Applies to database tables that have a multiple-field primary

key.

• Insure that each non-key field relates to the entire multiple-

field primary key.

• Place fields that do not describe the entire multiple-field

primary key in a separate table.

multiple-field primary key

• Problems in the Employee Table

– Unrelated non-key fields: Last Name, First Name,

Department fields

Page 12: Database Normalization Lynne Weldon July 17, 2000

12

Second Normal Form Established

• This table has a multiple-field primary key.

• Each non-key field relates to the entire primary key. All other fields were placed in a new table.

Page 13: Database Normalization Lynne Weldon July 17, 2000

13

Establishing Third Normal Form

• Applies to database tables that have a single-field primary key.

• Each non-key field is a fact about the primary key.

• Place fields that do not describe the single-field primary key in

a separate table.

• Problems in the Employee Table

– Unrelated non-key fields: Department Name, Dept Bldg

single-field primary key

Page 14: Database Normalization Lynne Weldon July 17, 2000

14

Third Normal Form Established

• Applies to tables with

a single-field

primary key.

• Each non-key field is

a fact about the

primary key.

About Employees

About Departments

• These values do not

describe the key;

they are put in a

separate table.

Page 15: Database Normalization Lynne Weldon July 17, 2000

15

Employee Database in 3rd Normal Form

Projects Table

Departments Table

Employees Table

Page 16: Database Normalization Lynne Weldon July 17, 2000

16