Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The MySQL Workshop

You're reading from   The MySQL Workshop A practical guide to working with data and managing databases with MySQL

Arrow left icon
Product type Paperback
Published in Apr 2022
Publisher Packt
ISBN-13 9781839214905
Length 726 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Scott Cosentino Scott Cosentino
Author Profile Icon Scott Cosentino
Scott Cosentino
Thomas Pettit Thomas Pettit
Author Profile Icon Thomas Pettit
Thomas Pettit
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1: Creating Your Database
2. Chapter 1: Background Concepts FREE CHAPTER 3. Chapter 2: Creating a Database 4. Chapter 3: Using SQL to Work with a Database 5. Chapter 4: Selecting, Aggregating, and Applying Functions 6. Section 2: Managing Your Database
7. Chapter 5: Correlating Data across Tables 8. Chapter 6: Stored Procedures and Other Objects 9. Chapter 7: Creating Database Clients in Node.js 10. Chapter 8: Working with Data Using Node.js 11. Section 3: Querying Your Database
12. Chapter 9: Microsoft Access – Part 1 13. Chapter 10: Microsoft Access – Part 2 14. Chapter 11: MS Excel VBA and MySQL – Part 1 15. Chapter 12: Working With Microsoft Excel VBA – Part 2 16. Section 4: Protecting Your Database
17. Chapter 13: Getting Data into MySQL 18. Chapter 14: Manipulating User Permissions 19. Chapter 15: Logical Backups 20. Other Books You May Enjoy Appendix

Normalization

Normalization is one of the most crucial skills for anyone planning to design and maintain databases. It's a design technique that helps eliminate undesirable characteristics such as insert, update, and delete anomalies and reduces data redundancy. Insert anomalies can come from the lack of primary keys, or the presence of functional dependency. Simply put, you will have duplicate records when there should be none.

If you have a big table with millions of records, the lookup, update, and deletion operations are very time-consuming. The first thing you can do is to give more resources to the server, but that does not scale well. The next thing to do is to normalize the table. This means you try to break up the big table you have into smaller ones and link the smaller tables by relationships using the primary and foreign keys.

This technique was first invented by Edgar Codd, and it has seven distinct forms called normal forms. The list goes from First Normal Form (1NF) to Sixth Normal Form (6NF), and one extra one, which is Boyce-Codd Normal Form (BCNF).

The first normal form states that each cell should contain a single value and each record should be unique. For example, suppose you have a database that stores information about employees. The first normal form implies that each column in your table contains a single piece of information, as shown here.

Figure 1.9 – Example of a table in 1NF

Figure 1.9 – Example of a table in 1NF

The second normal form means the database is in first normal, and it must also have a single-column primary key. With the previous example, you don't currently have a single unique column, since the employee name could duplicate, as well as the title and location. To convert it into a second normal form, you can add an ID as a unique identifier.

Figure 1.10 – Example of a table in 2NF

Figure 1.10 – Example of a table in 2NF

The third normal form requires the database to be in the second normal form and it is forbidden to have transitive functional dependencies. A transitive functional dependency is when a column in one table is dependent on a different column that is not a primary key. This means that every relationship in the database is between primary keys only. A database is considered normalized if it reaches the third normal form. The table here is in the third normal form, as it has a primary key that can be used to relate to any other tables, without the need for a non-key field:

Figure 1.11 – Example of a table in 3NF

Figure 1.11 – Example of a table in 3NF

For further details, you can visit the following site: https://docs.microsoft.com/en-us/office/troubleshoot/access/database-normalization-description.

Now that you have learned all about working with datasets, let's perform an activity to recap everything we have learned so far in this chapter.

You have been reading a chapter from
The MySQL Workshop
Published in: Apr 2022
Publisher: Packt
ISBN-13: 9781839214905
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image