Database Normalisation
Database Normalisation
com
1
Database Normalization
About Me
Mike Hillyer, BSc
• Member of the MySQL AB documentation team
• MySQL Core and Pro Certified
• Top MySQL expert at www.experts-exchange.com
• Resident MySQL expert at SearchDatabase.com
• http://www.openwin.org/mike/aboutme.php
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
3
About You
How many of you…
• Introduction
• What Is Database Normalization?
• What are the Benefits of Database Normalization?
• What are the Normal Forms?
• First Normal Form
• Second Normal Form
• Forming Relationships
• Third Normal Form
• Joining Tables
• De-Normalization
• Conclusion
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
5
Our Table
user
One Solution
user
Satisfying 1NF
user
PK user_id
first_name
last_name
phone
nickname email
address PK phone_id
city PK email_id
province country_code
postal_code address number
country extension
web_url
company
department
picture
notes
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
12
Forming Relationships
• Three Forms
– One to (zero or) One
– One to (zero or) Many
– Many to Many
• One to One
– Same Table?
• One to Many
– Place PK of the One in the Many
• Many to Many
– Create a joining table
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
13
Joining Tables
user phone
user_phone
PK user_id PK phone_id
PK,FK1 phone_id
PK user_id
first_name country_code
last_name number
type
nickname extension
address
city
province
postal_code
country email
web_url
PK address
picture
notes
FK1 user_id
email_format
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
14
user phone
user_phone
PK user_id PK phone_id
PK,FK1 phone_id
PK user_id
first_name country_code
last_name number
type
nickname extension
address
city
province
postal_code
country email
web_url
PK address
picture
notes
FK1 user_id
email_format
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
15
Satisfying 2NF
Satisfying 3NF
user_phone
phone
user
PK,FK1 user_id
PK phone_id
PK user_id PK,FK2 phone_id
country_code
first_name extension
number
last_name
type
nickname
address
city
email province
postal_code user_company
PK address country company
PK,FK1 user_id
web_url
PK,FK2 company_id PK company_id
FK1 user_id picture
format notes
department name
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
19
Finding Balance
user user_phone phone type country
PK user_id PK,FK1 user_id PK phone_id PK type_id PK country_id
PK,FK2 phone_id
first_name
FK1 type_id type Name
last_name extension area_code phone_code
nickname
NXX
unit
NCX
street_number
email FK2 country_id
street_name
street_type PK address
quadrant
user_department department
web_url FK1 user_id
picture format PK,FK1 user_id PK department_id
notes PK,FK2 department_id
FK1 postal_code
name
FK1 company_id
Joining Tables
De-Normalizing Tables
Conclusion
• http://dev.mysql.com/tech-resources/articles/intro-to-
normalization.html
• MySQL Database Design and Optimization
– Jon Stephens & Chad Russell
– Chapter 3
– ISBN 1-59059-332-4
– http://www.openwin.org/mike/books
• http://www.openwin.org/mike/presentations
200502-02 | Database Normalization | © MySQL AB 2005 | www.mysql.com
23
QUESTIONS?
Book Draw!