Learning SQL, Second Edition: Mastering SQL Fundamentals

320 Pages
by Alan Beaulieu
O’Reilly Media, Inc.

Review by Bill Coan

Relational Database Theory and Practice for the Beginner

Microsoft Word and SQL might not seem to have much to do with each other, but anyone who has tried to do a mail merge from a complex database has probably wished for greater understanding of the SQL language. And anyone who has developed an enterprise system for Microsoft Word documents, templates, or workflows has undoubtedly bumped up against the need to track user actions and preferences in a database or to help users extract data from an external corporate database.

As a result, ultimately Word and SQL do have something to do with each other. So, wouldn’t it be great if your first study guide on databases covered database theory in general, your own favorite database server in particular, and also the ins and outs of SQL?

Alan Beaulieu’s Learning SQL comes as close as possible to covering exactly those three topics, and it covers them with clarity, completeness, enthusiasm, and scrupulous attention to the reader’s needs.

When I say the book comes “as close as possible” to covering the designated topics, I’m making allowance for the fact that the examples in the book rely on MySQL Community Server, the no cost, freely available, open source database server.

The author recommends that you download and install MySQL and load the sample database so that you can run the examples and experiment with the data. In most cases, though, the examples will run on Oracle Database and SQL Server without modification, and in any case, when modifications are needed, they are provided in the text. Also, in point of fact, almost all of the SQL statements can be used in any application (e.g., Microsoft Access) that relies on SQL to query data.

The book starts by considering the challenges of storing data efficiently. It very briefly explores the history of computerized databases, including the rise of relational concepts and the development of SQL. Then the book introduces a very simple, easy-to-understand database of banking operations and begins to explore how data in the various tables can be added, modified, and deleted through the power of SQL.

The book’s strength lies in its careful unfolding of concepts and examples. At no point are you asked to digest more than one concept at a time, and with each new concept, concrete examples are provided to illustrate the concept and cement your understanding.

The book takes note of the fact that SQL statements can be divided into schema statements, data statements, and transaction statements. The bulk of the book is devoted to explication of data statements, but schema statements are also covered fairly extensively in a chapter on creating and populating a database and in a separate chapter devoted to meta data. Transaction statements also receive a dedicated chapter.

Early in the book, a “Query Primer” demonstrates how to think about and exploit the power of SELECT, FROM, and WHERE clauses of standard queries. From there, the book proceeds to filtering, updating, and deleting, before proceeding to queries involving multiple tables. A chapter on basic set theory (“Working with sets”) is very well done and includes highly graphical presentations. Additional chapters cover data generation, conversion, and manipulation, aggregation, subqueries, conditional logic, indexes and constraints, and data views (i.e., interfaces to shield users from the complexity of the underlying data).

The entire book is well written and thoughtfully organized. As you read along and follow the examples, your reaction is likely to be, “Aha! This new concept is simple and easy to grasp, just like the last one!” And, indeed, Beaulieu does an excellent job of breaking down the complexities of database theory and the SQL language into fundamental underlying concepts that anyone can understand.

The book is so readable that you won’t have any trouble breezing through it from start to finish in the order presented, but if you want to dip into it for reference purposes, the detailed table of contents and extensive index will allow you to do so. Either way, after just 320 pages of highly illustrated text, you will feel in complete command of SQL fundamentals.