6.5. Why Be Normal?

The database software that most Rails programs use — MySQL, PostgreSQL, and Oracle — all belong to a database structure known as a relational database, in contrast to a flat database, (such as a CSV text file), a hierarchical database (such as an XML structure), or an object-oriented database (such as ... well, nothing you've probably ever heard of, but like the Loch Ness Monster, you do hear about sightings of OO databases from time to time).

6.5.1. A Little Bit of Theory

Although databases may seem like one of the most pragmatic of all software, in fact, there's a huge amount of theory behind the structure and design of relational databases — although, to be fair, a true database purist would argue that none of the popular databases that call themselves relational actually adhere to the strict relational model. Be that as it may, much of the theory of relational database design is concerned with various kinds of normalization. A full discussion of all the various flavors of normalization (Wikipedia lists a solid nine named forms) is beyond the scope of this book (and frankly, I think it may be beyond my humble ability to comprehend).

However, the basic idea behind normalization is simple enough: use the structure of the database to ensure database integrity. In general, this involves keeping unrelated data in separate tables such that data is not duplicated. In your classic Order/Customer database, for example, an un-normalized database might include customer ...

Get Professional Ruby on Rails™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.