Second normal form

Achieving second normal form (2NF) means that you first do everything to achieve 1NF, then you make sure that all non-key fields are dependent on the primary key. For example, in our BadTable table from earlier, each row had one person in and also contained their company name, company address, and such.

To get to second normal form from there, you would analyse each column, and decide whether it depends on the primary key or not. In BadTable, the primary key is the ID number of a person, so let's go through the fields:

  • Name: Yep, a person's name is directly relevant to their ID

  • Address 1: Yep, same again

  • Address 2: Yep

  • Company Name: No. A person works for a company, but that does not relate directly to their ID - it relates to the company.

  • Company Address1: No. Company address is totally irrelevant in a table of people.

  • Company Address2: No, same again

  • Company City: No.

So, given that everything to do with the company is not directly related to the person, it should be split off into its own table and replaced with just a company ID number. This ID number is the row number from the companies table, and each person who works at a company should have their company's ID number in their entry.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Other normal forms >>

Previous chapter: First normal form

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.