Chapter 10: Normalizing your Database
When we are talking about SQL, normalization is the process of taking your database and breaking it up into some smaller units.
Developers will often use this procedure as a way to make your database easier to organize and manage.
Some databases are really large and hard to handle.
If you have thousands of customers, for example, your database could get quite large.
This will make it difficult to get through all the information at times because there is just so much that you will have to filter through to get what you want. 
But with database normalization, this is not as big of an issue.
The developer will be able to split up some of the information so that the search engine is better able to go through the database without taking so long or running into as many issues.
In addition, going through with database normalization will help to ensure the accuracy and integrity of all the information that you place into the database. 
How do I normalize the database?
Now that you know some of the reasons for choosing to do database normalization, it is time to work on doing the actual process.
The process of normalization basically means that you are going to decrease any of the redundancies that are inside the database.
You will be able to use this technique any time that you want to design or even redesign your database.
Some of the tools that you need and the processes that you should learn to make this happen will include:
Raw databases
Any database that hasn’t gone through the process of normalization can contain tables that have the same information inside of it.
This redundant information can slow down the search process and can make it really hard for your database to find the information that you want.
Some of the security issues that you could have with a database that hasn’t gone through normalization include slow queries, inefficient database updates, and poor security. 
This is all because you have the same information in there a few times, and you haven’t divided it into smaller pieces to make things easier on your search.
Below is an example of a database that will need some help with normalization.
00001.jpeg
As you can see, there are quite a few points where the same information is asked several times.
And while this is a small table, some of the bigger ones could have more issues that will really slow down the results and end up in a mess.
Using the process of normalization on your original database can ensure that you are going to cut out some of this mess and make things better for the user and for yourself to find the information needed. 
Logical design
Each of the databases that you are working on needs to be created as well as designed with the end-users in mind. 
You can make a fantastic database, but if the users find that it is difficult to navigate, you have just wasted a lot of time in the process.
Logical model, or logical design, is a process where you are going to be able to do this because you have arranged the data into smaller groups that are easy for the user to find and work with. 
When you are creating the data groups, you must remember that they should be manageable, organized, and logical.
Logical design is going to make it easier for you to reduce, and in some cases even eliminate, any of the data repetition that goes on in your database. 
What are the needs of the end-user?
When you are designing your database, it is important to keep the end-users needs in mind.
The end-users are the ones who will be using the database that you develop, so you will need to keep some of your personal feelings out of this and just concentrate on picking out a way to work the database that is beneficial to the customer. 
In general, you will want to create a database that is user-friendly, and if you are able to add in an intuitive interface, this can be great too.
Good visuals are a way to attract the customer, but you need to have excellent performance present as well, or the customer may get frustrated with what you are trying to sell them on the page. 
When you are working on creating a new database for your business, some of the questions that you should answer to ensure that you are making the right database for your customers include:
Data repetition
When creating your database, you need to make sure that the data is not repetitive.
You need to work to minimize this redundancy as much as possible.
For example, if you have the customers name in more than one table, you are wasting a lot of time and space in the process because this duplicated data is going to lead to inefficient use of your storage space. 
Outside of wasting the storage space, this repetitive entry will lead to confusion.
This is going to happen when the data in one of the tables don’t match up with a different one, even when the tables were created for the same person or object. 
Normal forms
A normal form will be a method of identifying the levels or the depth that you will need to normalize the database.
In some cases, it just needs to be cleaned up a little bit, but other times you will have a lot of work ahead of you to make that table look nice.
When you are using the normal form, you are going to determine what level of normalization you need to perform on the database.
There are three forms that you will use for normalizing the databases, including the first form, the second form, and the third form. 
Every subsequent form that you use will rely on the techniques that you used on the form before it.
With this, you need to have it in the right form before you can move on.
For example, you are not able to skip from the first form to the third form without doing the second form there as well. 
Once the tables are designed, the user will be able to assign a primary key to either some or each of the tables.
To attain this first form, you will divide up the data into small units, and each one needs to have two things; a primary key and also be free from any redundant data. 
Then this data can be transferred over to a new table as well.
This will help to sort out the important information and will leave behind redundant information or other things that you don’t need. 
This will help to get rid of the information that is in the way and slowing down the computer and will ensure that you are getting rid of the redundant and unneeded information along the way. 
Naming conventions
When you are working on the normalization process, it is a good idea to worry about the naming conventions.
You will need to use the names in order to store and then later retrieve your data.
You should pick out names that are relevant in some way to the information that you are working on so that it is easier to remember these names later on.
This will help to avoid confusion and keep things organized in the database.
Benefits of normalizing your database
We have spent some time talking about normalization in your database so far in this guidebook, but what are the benefits?
Why should you go through this whole process simply to clean out the database that your customers are using?
Wouldn’t it work out just fine to leave the information and let the search figure it out regardless of the redundancies and other information that you don’t need?
There are many benefits to doing this process including:
It may seem like a hassle to go through and normalize the database, but it really makes the whole experience better.
Your customers will have a better time finding the information that they want, the searching and purchasing process will become more streamlined, and your security will be top of the line. 
One thing to keep in mind, though is that, there is a downside to using normalization.
This process does reduce the performance of the database in some cases.
A normalized database is going to need more input/output, processing power, and memory to get the work done.
Once normalized, your database is going to need to merge data and find the required tables to get anything done.
While this can help to make the database system more effective, it is still important to realize that there are some downsides. 
Denormalization
Another process that you may wish to learn about is denormalization.
This allows you to take a normalized database and change it so that the database is able to accept repetition.
This is going to be used in some cases in order to increase how well the database is able to perform.
While there are some benefits to using the normalization process, it is going to slow down the system of the database simply because it is working through so many automated functions.
Depending on the case, it could be better to have this redundant information rather than working with a system that is slow. 
Normalization of your database has many great benefits, and it is pretty easy to set it all up.
You just need to teach the database to get rid of information that it finds repetitive, or that could be causing some of the issues within your system.
This can help to provide more consistency, flexibility, and security on the whole system.