DEV Community

samrlikespie
samrlikespie

Posted on

Database Normalization

Hello everyone, in this blog I will be going over Database Normalization.

Normalization is used in databases to reduce redundancies and overall simplify the information being stored to only the data you need which is stored only where its needed.

When addressing normal form there are 6 forms to look out for, but in this post we will just be going over the first two, 1NF and 2NF. (anything after 3NF is rarely if ever used anyways)

1NF is the first and base level of normalization forms. Each form builds off the one before it. This means that, for instance, 2NF must have all the same qualities that 1NF has plus more.

For an example I will use my behavior table.
Alt Text

In order for this database to be 1NF it must pass all three of these properties:

  1. The data must be stored in tables with rows uniquely identified by a primary key
  2. Data within each table must be stored in individual columns in reduced form
  3. There can not be any repeating groups

The table above fits all these requirements as all of the data is reduced, unique, and under a primary key.

Next we take a look at the 2nd normal form.
Here we have to make sure that everything from 1NF applies as well as now making sure that only data that relates to the table's primary key is included in the table.
Alt Text
Here we see a table where all of 1NF applies, but there is an error with 2NF. LevOfProcedure does not fit in with the table's primary key. This variable applies to the occupation itself and not to the actual person doing the job like the other variables in the table. To remove this variable I used an alter command which is shown in the video.
https://drive.google.com/file/d/1gZyL4rqHi7QIADXklZ5bFW_fv2IrLOur/view
Thanks for reading.

Top comments (0)