Preface to the First Edition

SQL is ubiquitous. But SQL is hard to use: It’s complicated, confusing, and error prone (much more so, I venture to suggest, than its apologists would have you believe). In order to have any hope of writing SQL code that you can be sure is accurate, therefore—meaning code that does exactly what it’s supposed to do, no more and no less—you must follow some appropriate discipline. And it’s the thesis of this book that using SQL relationally is the discipline you need. But what does this mean? Isn’t SQL relational anyway?

Well, it’s true that SQL is the standard language for use with relational databases—but that fact in itself doesn’t make it relational. The sad truth is, SQL departs from relational theory in all too many ways; duplicate rows and nulls are two obvious examples, but they’re not the only ones. As a consequence, the language gives you rope to hang yourself with, as it were. So if you don’t want to hang yourself, you need to understand relational theory (what it is and why); you need to know about SQL’s departures from that theory; and you need to know how to avoid the problems they can cause. In a word, you need to use SQL relationally. Then you can behave as if SQL truly were relational, more or less, and you can enjoy the benefits of working with what is in effect a truly relational system.

Now, a book like this wouldn’t be needed if everyone was using SQL relationally already—but they aren’t. On the contrary, I observe much bad practice ...

Get SQL and Relational Theory, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.