database management systems 4 - normalization

20
Database Management Systems Data Modelling Part 2 Normalization By Nickkisha Farrell, BSc IT, Dip Ed February 2014

Upload: nickkisha-farrell

Post on 28-Nov-2014

1.390 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Database Management Systems 4 - Normalization

Database ManagementSystems

Data Modelling Part 2Normalization

By Nickkisha Farrell, BSc IT, Dip Ed

February 2014

Page 2: Database Management Systems 4 - Normalization

IN THIS PRESENTATION

Entity and Referential Integrity

Normalization - 1st , 2nd , 3rd Normal Forms

2

Physical Database Design: tables, primary keys, foreign keys

Top-down versus Bottom-up Design

Page 3: Database Management Systems 4 - Normalization

TABLES / RELATIONS

3

When creating a table also called a relation:

• Each attribute value must be a single value only.

• All values for a given attribute must be of the same data type.

• Each attribute (column) name must be unique.

• The order of attributes (columns) is insignificant

• No two tuples (rows) in a relation should be identical.

• The order of the tuples (rows) is insignificant.

Page 4: Database Management Systems 4 - Normalization

ENTITY AND REFERENTIAL INTEGRITY

• An Entity typically corresponds to a relation.• Thus an entity’s attributes become attributes of therelation.

• These attributes are represented by columns in arelation

4

Page 5: Database Management Systems 4 - Normalization

KEYS

• Keys play a very important role in relational databases. Theyare used to establish and identify relationships betweentables. They are also ensure that each record can be uniquelyidentified by a combination of one or more field found in atable.

5

Page 6: Database Management Systems 4 - Normalization

PRIMARY & FOREIGN KEYS

6Foreign KeyA field in a table that matches the primary key column of another table. Thepurpose of the foreign key is to ensure referential integrity of the data. In otherwords, only values that are supposed to appear in the database are permitted.

Foreign KeyA field in a table that matches the primary key column of another table. Thepurpose of the foreign key is to ensure referential integrity of the data. In otherwords, only values that are supposed to appear in the database are permitted.

Page 7: Database Management Systems 4 - Normalization

FUNCTIONAL DEPENDENCIES

7

• Describes a relationship between attributes within a single table.

• An attribute is functionally dependent on another if we can usethe value of one attribute to determine the value of another.

• Example: Employee_Name is functionally dependent onSocial_Security_Number because Social_Security_Number can beused to uniquely determine the value of Employee_Name.

The arrow symbol → is used to indicate a functional dependency.X → Y is read X functionally determines Y

Page 8: Database Management Systems 4 - Normalization

FUNCTIONAL DEPENDENCIES

8

Here are a few more examples:- Student_ID → Student_Major- Semester → Grade, Course_Number- TaxRate → Car_Price• The attributes listed on the left hand side of the → arecalled determinants.

• One can read A → B as:• A Determines B• Given a value for A, we can determine one value for B.

Page 9: Database Management Systems 4 - Normalization

NORMALIZATION

• Normalization is a process in which we systematicallyexamine relations for anomalies and, whendetected, remove those anomalies by splitting upthe relation into two new, related, relations.

9

In a nut shell Normalization is the process ofefficiently organizing data in a database.

Page 10: Database Management Systems 4 - Normalization

NORMALIZATION

• Normalization is a relational database concept. If you havecreated a correct entity model, then the tables createdduring design will conform to the rules of normalization.

• Normalization can also be thought of as a trade-off betweendata redundancy and performance. Normalizing a relationreduces data redundancy but introduces the need for joinswhen all of the data is required by an application such as areport query.

10

Page 11: Database Management Systems 4 - Normalization

NORMAL FORMS

• There are a series of guidelines for ensuring thatdatabases are normalized. These are divided into

• 1NF – First Normal Form• 2NF – Second Normal Form• 3NF – Third Normal Form• 4NF – Forth Normal Form• 5NF – Fifth Normal Form• BCNF – Boyce & Codd Normal Form

• 4NF and 5NF are rarely seen and won't be discussed inthis chapter.

11

“Third normal form is the generallyaccepted goal for a database design

that eliminated redundancy.”

Page 12: Database Management Systems 4 - Normalization

NORMALIZATION RULES

12

Normal Form Rule DescriptionFirst Normal Form The table contains no duplicative groups i.e. no

columns are repeated.

Second Normal Form (2NF) The Table must be in 1NF.

An attribute must be dependent upon entity’sentire unique identifier.

Third Normal Form (3NF) The Table must be in 2NF.

No non-UID attribute can be dependent onanother non-UID attribute.

“Each non-primary key value MUST be dependent on thekey, the whole key, and nothing but the key.”

Page 13: Database Management Systems 4 - Normalization

FIRST NORMAL FORM – 1NF

13

• Steps to Remove Repeating Groups1. Remove the repeating columns from the original table.2. Create separate tables for each group of related data3. Identify each row with a unique column or set of columns

(the primary key).4. Create a foreign key in the new table to link back to the

original table.

The table must express a set of unordered, two-dimensional table structures.A table is considered in the first normal form if it contains no repeating groups.

Page 14: Database Management Systems 4 - Normalization

2ND NORMAL FORM

14

A relation is in second normal form (2NF) if it is in 1NF and all of its non-keyattributes are dependent on all of the key.

• Another way to say this: A relation is in second normal formif it is free from partial-key dependencies

• Relations that have a single attribute for a key areautomatically in 2NF.

Page 15: Database Management Systems 4 - Normalization

2ND NORMAL FORM

15

• Steps to Remove Partial Dependencies1. Determine which non-key columns are only partially

dependent upon the table’s primary key.2. Remove those columns from the base table.3. Create a second table with those non-keyed columns an

assign an appropriate primary key.4. Create a foreign key from the original base table to the

new table, linking to the new primary key.

Page 16: Database Management Systems 4 - Normalization

3RD NORMAL FORM

• Steps to Remove Transitive Dependencies1. Determine which columns are dependent on another non-

keyed column.2. Remove those columns from the base table.3. Create a second table with those columns and the non-

key columns that they are dependent upon.4. Create a foreign key in the original table linking to the

primary key of the new table.16

A relation is in third normal form (3NF) if it is in second normal form andit contains no transitive dependencies.

Page 17: Database Management Systems 4 - Normalization

TOP-DOWN DESIGN VS BOTTOM UP DATABASESCHEMA DESIGN

17

• TOP DOWN• Identifies the data sets and then defines the data

elements for each of those sets. That is entity typesare defined followed by each entity’s attributes, oftenrepresented by ER modelling.

• BOTTOM UP• First identifies the data elements and then groups them

together in data sets i.e. it first defines attributes andthen groups them to form entities

Page 18: Database Management Systems 4 - Normalization

18

ConceptualModel

ConceptualModel

Entity

AttributeAttribute AttributeAttribute

Entity

AttributeAttribute AttributeAttribute

Top Down Bo

ttom

Up

TOP-DOWN DESIGN VS BOTTOM UP DESIGN

Page 19: Database Management Systems 4 - Normalization

SUMMARY

An entity relationship model transforms intonormalized data design.

19

1NF - The table must express a set of unordered, twodimensional tables. The table cannot contain repeating groups.1NF - The table must express a set of unordered, twodimensional tables. The table cannot contain repeating groups.

2NF - The table must be in 1NF. Every non-key column must bedependent on all parts of the primary key.2NF - The table must be in 1NF. Every non-key column must bedependent on all parts of the primary key.

3NF - The table must be in 2NF. No non-key column may befunctionally dependent on another non-key column.3NF - The table must be in 2NF. No non-key column may befunctionally dependent on another non-key column.

Page 20: Database Management Systems 4 - Normalization

REFERENCES

20

• Gillenson, Mark L.,2012, Fundamentals of DatabaseManagement Systems / Mark L. Gillenson.—2nd ed., JohnWiley and sons inc

• http://holowczak.com/database-normalization/

• http://www.darkopetrovic.com/pdf/Data-Modeling-and-

Relational-Database-Design.pdf• http://databases.about.com/od/specificproducts/a/normali

zation.htm