DATABASE DESIGN
USING MYSQL
Principles & Normalization
RELATIONAL MODEL RULES
• Each column value must be a single value only.
• All values for a given column must be of the same
data type.
• Each column name must be unique.
• The order of columns is insignificant
• No two rows in a relation can be identical.
• The order of the rows is insignificant.
FUNCTIONAL DEPENDENCIES
A Functional Dependency describes a relationship
between columns within a single relation.
• A column is dependent on another if one value can
be used to determine the value of another.
• Example: first_name is functionally dependent on id
because id can be used to uniquely determine the
value of first_name
COMMON DESIGN MISTAKES
• Tables with too many fields or with fields that do not
relate to each other
• Too many tables with similar data
• Repeated rows
• Using comma separated values or multiple values in
a single row
• Poor naming conventions
• Poor or no planning
• Non-Normalized data
DATABASE NORMALIZATION
Normalization is the process of organizing the fields
and tables of a relational database to
minimize redundancy and dependency
This can involve dividing larger tables into smaller
tables and defining relationships between them.
The objective is to isolate data so that actions in a
field can be made in one table and then
propagated through the rest of the needed tables
using properly defined relationships.
FIRST NORMAL FORM (1NF)
• No repeating or duplicate fields
• Each row should contain only one value
• Each row/record should be unique and
identified by a primary key
1NF EXAMPLE
id name membership
01 John Doe silver
01 John Doe gold
02 Steve Smith gold
id name
01 John Doe
02 Steve Smith
id customer_id membership
01 01 silver
02 01 gold
03 02 gold
Customers
Table
(WRONG)
Customers
Table
(RIGHT)
Memberships
Table
(RIGHT)
SECOND NORMAL FORM (2NF)
• Should be in 1NF
• All non-key fields depend on all components of
the primary key
• No partial dependencies
2NF EXAMPLE
id name membership_id membership
01 John Doe 02 silver
02 Steve Smith 01 gold
id name
01 John Doe
02 Steve Smith
id customer_id membership
01 01 silver
02 01 gold
03 02 gold
Customers
Table
(WRONG)
Customers
Table
(RIGHT)
Memberships
Table
(RIGHT)
THIRD NORMAL FORM (3NF)
• Should be in 2NF
• Every non-prime attribute of table must depend
on primary key
3NF EXAMPLE
id name street city zip
01 John 2 Main Amesbury 01913
02 Steve 4 School Merrimac 01860
id name zip
01 John Doe 01913
02 Steve Smith 01860
zip street city
01913 2 Main Amesbury
01860 4 School Merrimac
Customers
Table
(WRONG)
Customers
Table
(RIGHT)
Address
Table
(RIGHT)
THAT’S IT!

Learn Database Design with MySQL - Chapter 5 - Design principles & normalization

  • 1.
  • 2.
    RELATIONAL MODEL RULES •Each column value must be a single value only. • All values for a given column must be of the same data type. • Each column name must be unique. • The order of columns is insignificant • No two rows in a relation can be identical. • The order of the rows is insignificant.
  • 3.
    FUNCTIONAL DEPENDENCIES A FunctionalDependency describes a relationship between columns within a single relation. • A column is dependent on another if one value can be used to determine the value of another. • Example: first_name is functionally dependent on id because id can be used to uniquely determine the value of first_name
  • 4.
    COMMON DESIGN MISTAKES •Tables with too many fields or with fields that do not relate to each other • Too many tables with similar data • Repeated rows • Using comma separated values or multiple values in a single row • Poor naming conventions • Poor or no planning • Non-Normalized data
  • 5.
    DATABASE NORMALIZATION Normalization isthe process of organizing the fields and tables of a relational database to minimize redundancy and dependency This can involve dividing larger tables into smaller tables and defining relationships between them. The objective is to isolate data so that actions in a field can be made in one table and then propagated through the rest of the needed tables using properly defined relationships.
  • 6.
    FIRST NORMAL FORM(1NF) • No repeating or duplicate fields • Each row should contain only one value • Each row/record should be unique and identified by a primary key
  • 7.
    1NF EXAMPLE id namemembership 01 John Doe silver 01 John Doe gold 02 Steve Smith gold id name 01 John Doe 02 Steve Smith id customer_id membership 01 01 silver 02 01 gold 03 02 gold Customers Table (WRONG) Customers Table (RIGHT) Memberships Table (RIGHT)
  • 8.
    SECOND NORMAL FORM(2NF) • Should be in 1NF • All non-key fields depend on all components of the primary key • No partial dependencies
  • 9.
    2NF EXAMPLE id namemembership_id membership 01 John Doe 02 silver 02 Steve Smith 01 gold id name 01 John Doe 02 Steve Smith id customer_id membership 01 01 silver 02 01 gold 03 02 gold Customers Table (WRONG) Customers Table (RIGHT) Memberships Table (RIGHT)
  • 10.
    THIRD NORMAL FORM(3NF) • Should be in 2NF • Every non-prime attribute of table must depend on primary key
  • 11.
    3NF EXAMPLE id namestreet city zip 01 John 2 Main Amesbury 01913 02 Steve 4 School Merrimac 01860 id name zip 01 John Doe 01913 02 Steve Smith 01860 zip street city 01913 2 Main Amesbury 01860 4 School Merrimac Customers Table (WRONG) Customers Table (RIGHT) Address Table (RIGHT)
  • 12.