Presentation is loading. Please wait.

Presentation is loading. Please wait.

Normalization ACSC 425 Database Management Systems.

Similar presentations


Presentation on theme: "Normalization ACSC 425 Database Management Systems."— Presentation transcript:

1 Normalization ACSC 425 Database Management Systems

2 Overview What is normalization? What are the normal forms?
How to normalize relations?

3 Introduction Question:
How many, and what, relations (tables) should be used to store my data? Is the current relation free of problems?

4 Normalization Normalization is a process of producing a set of related relations(tables) with desirable attributes, given the data requirements of a domain The goal is to remove redundancy and other data modification (insertion, update and deletion) problems Usually dividing a table into 2 or more tables Using Normal Forms as a guide

5 Normal Forms Fewer abnomallies... Normalization …but more tables
Normal forms are guidelines (steps) for the normalization process Fewer abnomallies... Normalization …but more tables Unnormalized Form (UNF) 1st Normal Form (1NF) 2nd Normal Form (2NF) 3rd Normal Form (3NF) Boyce Codd Normal Form (BC/NF) 4th Normal Form (4NF) 5th Normal Form DK/NF

6 Normalization – 1NF A table is in 1NF if
it satisfies the definition of a relation Review: what are the characteristics of a relation? No “repeating groups” (columns)

7 Relation A relation is a two-dimensional table that has specific characteristics: The table consist of rows and columns Rows contain data about entity instances All values in a row describes the same entity instance Columns contain data about attributes of the entity All values in a column are of the same kind 7

8 Relation (continued) Relation’s specific characteristics go on:
Each row is distinct A Cell of the table hold a single value Each column has a unique name The order of the rows is unimportant The order of the columns is unimportant 8

9 Repeating Groups Customer ID First Name Surname Telephone Number 123
Robert Ingram 456 Jane Wright 789 Maria Fernandez Customer ID First Name Surname Tel. No. 1 Tel. No. 2 Tel. No. 3 123 Robert Ingram 456 Jane Wright 789 Maria Fernandez

10 Transforming to 1NF Transforming to rows, rather than columns
Customer ID First Name Surname Telephone Number 123 Robert Ingram 456 Jane Wright 789 Maria Fernandez

11 Transforming to 1NF: Example
Another example UNF 1NF

12 Problems in 1NF Basically has the same problem as the spreadsheet tables Redundancy Data may be inconsistent after modification

13 Non-Relation Examples
Single value Column same kind, row describes the complete instance 13

14 Non-Relation Examples (2)
Emp_Name Emp_Age Emp_Phone Emp_ Jordan Hail 45 Jack Parsons 28 Tom Jackson 23 Liz Marsten Thirty Single value Column same kind, row describes the complete instance 14

15 Higher Normal Forms Normal forms higher than 1NF deal with functional dependency Identifying the normal form level by analyzing the functional dependency between attributes (fields)

16 Functional Dependency
If each value of attribute A is associated with only one value of attribute B, we say A determines B Or, B is dependent on A Denoted as: A  B Functional dependence describes relationships between attributes (not relations) Note: A (or B) could be a set of fields

17 Functional Dependency Examples
For each SSN, there is only one corresponding first name (or last name), so: SSN determines FirstName SSN  FirstName Non-dependency example Each instructor teaches multiple courses, so: InstructorId does not determines CourseNumber

18 Functional Dependency and Keys
By definition, a primary key (candidate key) functionally determines all other attributes Primary key Surrogate key Composite primary key Dependency diagram ISBN Title PubDate ListPrice

19 Functional Dependency Exercise
CustomerNum  CustomerName? {Street, City, State}  Zip? CustomerName  Balance? State (?) Zip RepNum ( ? ) CustomerName

20 Normalization – 2NF A relation is in 2NF, if Partial dependency A B C
It is in 1st normal formal, and All nonkey attributes must be functionally dependent on the whole primary key (Full dependency) No partial dependency It implies that a relation is in 2NF if there is a single-attribute primary key (candidate key) Partial dependency A non-key attribute is dependent on part of a primary key A B C D

21 Transforming to 2NF A B C D A B C B D Identify primary key (PK)
If PK consists of only one field, then it is in 2NF If PK is a composite key, then analyze functional dependency between part of primary key and other non-key attributes Move partial dependency involved attribute to another relation A B C D A B C B D

22 A Relation in 1NF but Not in 2NF
Partial dependency

23 Transforming to 2NF: Example
Order Order Product OrderItem

24 Problems in 2NF Again, redundancy and potential inconsistency

25 Normalization – 3NF A relation is in 3NF, if Transitive dependency
It is in 2nd normal formal, and All attributes must, and only, be functionally dependent on candidate keys No transitive dependency Transitive dependency A  B and B  C, then A  C A B C D

26 A Relation in 2NF but Not in 3NF
Identify primary key (PK) and Look for transitive dependence Transitive dependency

27 Transforming to 3NF Move the attributes involved in transitive dependency to another relation Order Customer

28 Some Practical Tips If there are attributes of two different entities in one table, there are usually problems To identify the normalization level, determine the primary key first; then look for partial dependence and transitive dependence Generally relations in the 3rd normalization forms are considered to be well formed; going higher may introduce unnecessary structural complexity which is inefficient for data queries Very often tables can go for lower normal forms (de-normalization) depending on design requirements

29 Normalization Exercise 1-1
Which normal form is the above table in? 1NF 2NF 3NF UNF

30 Normalization Exercise 1-2
Which normal form is the above table (2nd one) in? 1NF 2NF 3NF UNF

31 Normalization Exercise 1-3
Which normal form is the above table (first one) in? 1NF 2NF 3NF UNF

32 Normalization Exercise 1-4
Final database design with 3 tables

33 Summary

34 Summary Key concepts Normalization Normal forms Functional dependency


Download ppt "Normalization ACSC 425 Database Management Systems."

Similar presentations


Ads by Google