DEV Community

Matt Crilley
Matt Crilley

Posted on

Normalization of data in SQL

In this blog I will be going over what normalized data is and how I was able to implement it into my SQL database.

First, I will explain what normalized data is. There are multiple different levels to data normalization, but I will only be discussing the first two levels. The first level has three requirements it must meet to be considered first normal form. One requirement is that the data can be identified by a primary key and is in rows and columns. The second requirement is that the data is in its most reduced form. The final requirement is that there cannot be any repeats or redundancy within the data.

One example from my Covid-19 database that does not pass these requirements is within my behavior table.

Alt Text

In this table I have a column for attends group functions, and another column for social distances. Since you can assume that if somebody doesn't social distance then they also attend group functions this makes them redundant. To fix this I will get rid of the attends group functions column.

Next, we have the second normal form. This normal form has all of the same requirements from the first normal form, but the data must also relate directly to the primary key.

In my database I have a column named Patient in each of the different fields. The patient number does not directly relate to all of the fields such as hospital.

Alt Text

I can fix this by getting rid of the patient column in all of the fields except for the patient field.

I created the video below further explaining what normalized data is and how to adjust your database accordingly within SQL.

(Sorry it is in two video's I accidentally stopped recording during the first video and could not edit them together.)

Top comments (0)