The Art of SQL
The Art of SQL
By Stéphane Faroult with Peter Robson.
367 pp. O’Reilly Media, Inc. $44.99.
Some 2,500 years ago, Sun Tzu wrote a book that begins with these words:
“The art of war is of vital importance to the State. It is a matter of life and death, a road either to safety or to ruin. Hence it is a subject of inquiry which can on no account be neglected.”
Sun Tzu further says, “If you know the enemy and know yourself, you need not fear the result of a hundred battles.”
These are only two quotes from a book that even day contains so much truth that you can apply it to almost any circumstance. Sun Tzu’s book has been widely adapted to many different areas. It is surprising that no one has written “The Art of SQL” before. The book at hand now finally closes this gap. “The Art of SQL” follows Sun Tzu’s in its outline and thus the chapters are named:
- Laying Plans (Designing Databases for Performance)
- Waging War (Accessing Databases Efficiently)
- Tactical Dispositions (Indexing)
- Maneuvering (Thinking SQL Statements)
- Terrain (Understanding Physical Implementation)
- The Nine Situations (Recognizing Classic SQL Patterns)
- Variations in Tactics (Dealing with Hierarchical Data)
- Weaknesses and Strengths (Recognizing and Handling Difficult Cases)
- Multiple Fronts (Tackling Concurrency)
- Assembly of Forces (Coping with Large Volumes of Data)
- Stratagems (Trying to Salvage Response Times)
- Employment of Spies (Monitoring Performance)
If you own a copy of Sun Tzu’s “The Art of War,” you can’t help but smile while reading “The Art of SQL” because of the many analogies the author worked out. While the first of the above quote might translate to: “The art of SQL is to efficiently manage, query and analyze large volumes of data, which is of vital importance to today’s companies,” the second quote is even more evident: “Only when you know your data and know the language to query them, you need not fear a hundred project deadlines.”
Now “know the language” can mean all or nothing. Therefore, the author rightfully pinpoints that it is not sufficient just to produce functionally correct working code in this age of continuously expanding data, but it is necessary to write fast and efficient code right from the start. And to be able to write fast and efficient code, you not only have to be able to write SQL code, but also have to be able to think SQL and know SQL’s own logic.
This is where “The Art of SQL” comes into play. It is not a book for beginners. Nor is it a book exclusively for SQL Server users. Far from it. There are passages in the book where it becomes obvious that the author worked for Oracle and that this is the RDBMS of his choice. But that doesn’t impede your reading pleasure because the SQL code in the book is easily comprehended by SQL Server users and the explanations are true across RDBMS boundaries. And it certainly wouldn’t hurt anyone to look over the rim of his or her own coffee cup, right?
In this book, you’ll learn how to tackle bad SQL code and how to avoid writing it right from the start. The author moves from analysis and optimization of simple statements to choosing the right index to analysis of complex statements and embedded SQL in client languages. Although the book doesn’t provide any new insights, the does serve as a compendium of existing insights. Because it is also written from the point of view of writing SQL as a military maneuver, makes it doubly worth reading.