0% found this document useful (0 votes)
51 views18 pages

Chapter Add On 1

This document discusses database normalization and provides examples of different normal forms. It defines normalization as organizing data to minimize duplication and isolate data through defining relationships between tables. The goals of normalization are flexibility, data integrity, and efficiency. It describes first, second, and third normal form and provides examples of how to normalize data to those forms. Primary keys, relationships, and referential integrity are also covered. Considerations for when not to normalize are discussed and an example of normalizing school data is provided.

Uploaded by

Escada Bebey
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views18 pages

Chapter Add On 1

This document discusses database normalization and provides examples of different normal forms. It defines normalization as organizing data to minimize duplication and isolate data through defining relationships between tables. The goals of normalization are flexibility, data integrity, and efficiency. It describes first, second, and third normal form and provides examples of how to normalize data to those forms. Primary keys, relationships, and referential integrity are also covered. Considerations for when not to normalize are discussed and an example of normalizing school data is provided.

Uploaded by

Escada Bebey
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Database Normalization

BIT 2083
FTMM, UTHM

1
Overview
• Introductions
• The Normal Forms
• Primary Key
• Relationships and Referential Integrity
• When NOT to Normalize
• Real World Exercise
• Resources

BIT 2083 2
Introductions
• TJ Racoosin
• You
– Are you familiar with normalization?
– Used the relationship window ? Enforce
referential integrity? Cascade Delete?
– Any issues with normalizing data?

BIT 2083 3
Why Normalize?
• Flexibility
– Structure supports many ways to look at the data
• Data Integrity
– “Modification Anomalies”
• Deletion
• Insertion
• Update
• Efficiency
– Eliminate redundant data and save space

BIT 2083 4
Normalization Defined
• “ In relational database design, the process of
organizing data to minimize duplication.
• Normalization usually involves dividing a
database into two or more tables and defining
relationships between the tables.
• 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.”
- Webopedia, http://webopedia.internet.com/TERM/n/normalization.html

BIT 2083 5
Another Definition
• "Normalization" refers to the process of
creating an efficient, reliable, flexible,
and appropriate "relational" structure for
storing information. Normalized data
must be in a "relational" data structure.
- Reid Software Development, http://www.accessdatabase.com/normalize.html

BIT 2083 6
The Normal Forms
• A series of logical steps to take to
normalize data tables
• First Normal Form
• Second
• Third
• Boyce Codd
• There’s more, but beyond scope of this

BIT 2083 7
First Normal Form (1NF)
• All columns (fields) must be atomic
– Means : no repeating items in columns
OrderDate Customer Items
11/30/1998 Joe Smith Hammer, Saw, Nails
OrderDate Customer Item1 Item2 Item3
11/30/1998 Joe Smith Hammer Saw Nails
Solution: make a separate table for each set of
attributes with a primary key (parser, append query)
Customers Orders
CustomerID OrderID
Name Item
CustomerID
OrderDate BIT 2083 8
Second Normal Form (2NF)
• In 1NF and every non-key column is fully
dependent on the (entire) primary key
– Means : Do(es) the key field(s) imply the rest of the fields? Do we
need to know both OrderID and Item to know the Customer and
Date? Clue: repeating fields
OrderID Item CustomerID OrderDate
1 Hammer 1 11/30/1998
1 Saw 1 11/30/1998
1 Nails 1 11/30/1998

Solution: Remove to a separate table (Make Table)


Orders OrderDetails
OrderID OrderID
CustomerID Item
OrderDate
BIT 2083 9
Third Normal Form (3NF)
• In 2NF and every non-key column is mutually independent
– means : Calculations

Item Quantity Price Total


Hammer 2 $10 $20
Saw 5 $40 $200
Nails 8 $1 $8

•Solution: Put calculations in queries and forms


OrderDetails
Put expression in text control or in query:
OrderID
=Quantity * Price
Item
Quantity
Price
BIT 2083 10
Kumar Madurai: http://www.mgt.buffalo.edu/courses/mgs/404/mfc/lecture4.ppt
Boyce-Codd Form (3NF) - Examples
• A more restricted version of 3NF (known as
Boyce-Codd Normal Form) requires that the
determinant of every functional dependency in
a relation be a key - for every FD: X => Y, X is
a key
• Consider the following relation:
STU-MAJ-ADV (Student-Id, Major, Advisor)
Advisor => Major, but Advisor is not a key
• Boyce-Codd Normal Form for above:
STU-ADV (Student-Id, Advisor)
ADV-MAJ (Advisor, Major)
2/16/98 11 10
MGS 404
Primary Key
• Unique Identifier for every row in the
table
– Integers vice Text to save memory, increase
speed
– Can be “composite”
– Surrogate is best bet!
• Meaningless, numeric column acting as
primary key in lieu of something like SSN or
phone number - (both can be reissued!)

BIT 2083 12
Relationships
• One to many to enforce “Referential Integrity”

Two “foreign”
keys make a
A look up table - it
composite primary
doesn’t reference
key and “relate”
any others
many to many
tables

BIT 2083 13
Table Prefixes Aid Development
– First, we’ll get replace text PK with number
– The Items table is a “look up” with tlkp prefix
– tlkp “lookup” table (no “foreign keys”)
– OrderDetails is renamed “trelOrderItem” a “relational” table
• trel “relational” (or junction or linking)
– two foreign keys make a primary

OrderDetails
OrderID
Item trelOrderItem tblOrders
tlkpItems OrderID
OrderID
ItemID CustomerID
ItemID
ItemName OrderDate
BIT 2083 14
Referential Integrity
• Every piece of “foreign” key data has a
primary key on the one site of the relationship
– No “orphan” records. Every child has a parent
– Can’t delete records from primary table if in related table

• Benefits - Data Integrity and Propagation


– If update fields in main table, reflected in all queries
– Can’t add a record in related table without adding it to main
– Cascade Delete: If delete record from primary table, all
children deleted - use with care! Better idea to “archive”
– Cascade Update: If change the primary key field, will change
foreign key

BIT 2083 15
When Not to Normalize
• Want to keep tables simple so user can make
their own queries
– Avoid processing multiple tables
• Archiving Records
– If No need to perform complex queries or “resurrect”
– Flatten and store in one or more tables
• Testing shows Normalization has poorer
performance
– “Sounds Like” field example
– Can also try temp tables produced from Make Table queries

BIT 2083 16
Real World - School Data
Student Student Previous Current
Last First Parent 1 Parent 2 Teacher Teacher
Smith Renee Ann Jones Theodore Smith Hamil Burke
Mills Lucy Barbara Mills Steve Mills Hamil Burke
Jones Brendan Jennifer Jones Stephen Jones Hamil Burke ….
Street Address City State Postal Code Home Phone
5551 Private Hill Annandale Virginia 22003- (703) 323-0893
4902 Acme Ct Annandale Virginia 22003- (703) 764-5829
5304 Gains Street Fairfax Virginia 22032- (703) 978-1083 ….

First Year Last Year Age


Program Enrolled Attended Birthday inSept Map Coord Notes
PF /0 0 6/25/93 5 22 A-3
PF 96/97 0 8/14/93 5 21 F-3
PH 96/97 0 6/13/94 4 21 A-4

BIT 2083 17
One Possible Design

BIT 2083 18

You might also like