9.8.7 ConclusionThis is NOT the latest copy of this book; click here for the latest version.
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 see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|