Do you see how normalisation works? I hope so! Once you have the data split, you can do much more powerful things; for example, CompanyNum could be made to use a comma-separated list of companies that person has worked for, which would mean one field of "1,2" would mean "This person has worked for company 1 and company 2" - you would not have to add four more fields to each record to allow them to have worked for two companies.

How you normalise data might not be immediately apparent to you in your own projects, but it can make a big difference if done properly. Put simply, every individual thing which uniquely has attributes of its own in your database should have its own table of data - that is, if you were shipping computers, you might have a table for monitor types, a table for CPU types, a table for graphics card types, etc, and then a master table of PCs, which contained IDs into the other tables - e.g., PC #1 might contain monitor #4 (which in the Monitors table might be a Mitsubishi Diamond Plus 200), keyboard #6, graphics card #2, etc.

Final note: Planning your data structure ("database schema") should be done before you start work, because it is not really something that is easy to change after you start work!


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: Table joins >>

Previous chapter: Other normal forms

Jump to:


Home: Table of Contents

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