Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
Product_Name2
Product_Cost2
Product_Picture2
Order_Date
Order_Quantity
Shipper_Name
The table has been abbreviated, but it still portrays the general idea. Now, in your Customers table,
how could you add a new customer? You would have to add a product and an order as well. What if you
wanted to run a report that shows all the products you sell? You could not easily separate products from
customers in a simple SQL statement. The beauty of a relational database, if designed correctly, is that
you can do just that.

Normalization also makes things easier to understand. Humans tend to break things down to the lowest
common denominator. We do it with almost everything—from animals to cars. We look at a big picture
and make it less complex by grouping similar things together. The guidelines that normalization
provides create the framework to break down the structure. In your sample database, It is easy to see
that you have three distinct groups: customers, products, and orders. Following normalization
guidelines, you would create your tables based on these groups.

The normalization process has a name and a set of rules for each phase of breakdown/grouping. This
all may seem a little confusing at first, but I hope you will understand the process as well as the reasons
for doing it this way. Most people are happy with a spreadsheet that holds all their pertinent data. The
time it takes to break down your schema by going through the normalization process is well spent. It will
require less time to go through the process than it would to cut and paste your columns of data so they
fit the report the boss wants.

Another advantage to normalizing your database is space consumption. A normalized database will
take up less space overall than one that is not normalized. There is less repetition of data, so the actual
disk space that is consumed holding your data will be much smaller.

Degrees of Normalization


There are basically three steps of normalization. They are First Normal Form (1NF), Second Normal Form
(2NF) and Third Normal Form (3NF). Each form has its own set of rules. After a database conforms to a
level, it is considered normalized to that form. Say, for example, that your database conforms to all the rules
of the second level of normalization. It is then considered to be in Second Normal Form. Sometimes it is not
always the best idea to have a database conform to the highest level of normalization. It may cause an
unnecessary level of complexity that could be avoided if it were at a lower form of normalization.
Note There are a total of nine different rules of normalization. They are First Normal
Form, Second Normal Form, Third Normal Form, Boyce-Codd Normal Form,
Fourth Normal Form, Fifth Normal Form or Join-Projection Normal Form, Strong
Join-Projection Normal Form, Over-Strong Join-Projection Normal Form, and
Domain Key Normal Form. This book will only cover the first three forms of
normalization.


First Normal Form


The rule of First Normal Form states that all repeating columns should be eliminated and put into separate
tables. This is a pretty easy rule to follow. Take a look at the schema for the Customers database in Table
5.1.
Table 5.1 Schema for Customers Database


Customers
Customer_ID
Last_Name
First_Name
Address
Product_Name1
Product_Cost1
Free download pdf