SQL Cookbook
Simon P. Chappell writes "One of the staples of corporate I.S. development is processing data, and increasingly these days that data lives in a relational database. The lingua franca of relational database programming is the Structured Query Language (SQL), often pronounced "sequel". Many programmers find that the basics of SQL are easy to learn, but after that, it tends to get complicated. Enter the SQL Cookbook from O'Reilly." Read the rest of Simon's review.
SQL Cookbook
author
Anthony Molinaro
pages
595 (9 page index)
publisher
O'Reilly
rating
8/10
reviewer
Simon P. Chappell
ISBN
0596009763
summary
If you need help working with a database, this is the book for you.
The book is not for beginners and makes no efforts to teach any SQL. It concentrates purely on building on the base level of SQL knowledge that most programmers have. If you know the basics: Create, Read, Update and Delete (an unfortunate, yet memorable acronym) but rarely go beyond that, this book is for you. I know that I fall into this target market.
The point of the cookbook is that you need to get something done and you need to get it done sooner rather than later. Now, most of us can figure out most things given enough time, but in the real world, we rarely have enough time. The cookbooks objective is to save you time by giving you a successful approach that you could have figured out eventually anyway.
If you've previously read any other technology cookbook from O'Reilly, then you already know the structure of the recipes. For those new to the O'Reilly cookbook format, it's actually fairly straightforward. Each recipe starts out with a problem statement. Recipe one in chapter one, titled "Retrieving all Rows and Columns from a Table" has the problem statement "You have a table and want to see all of the data in it." Nice and clear. Then comes the solution. Naturally, for this problem statement we end up with a SELECT that looks like this:
Then the recipe has a discussion section where the solution is explained in more detail and the reasoning behind it is provided. For recipe one, the discussion explores the trade-offs between using the "*" to signify all columns versus naming each column explicitly.
The chapter structure through the book is very much one of building on the previous material. The first chapter starts with the fundamentals, the retrieving of records and then chapter two takes over with sorting the results of your query, while chapter three looks at using multiple tables.
Chapter four covers inserting, updating and deleting records. After that it's back into the world of queries, with chapter five exploring metadata queries for those times when you need to know just a little more about what's going on under the covers. Chapter six looks at working with Strings, a much harder topic than it would seem at first thought. Chapter seven addresses working with numbers and chapter eight does the same for date arithmetic with chapter nine bringing more understanding to general date manipulation. Chapter ten looks at working with ranges.
Chapter eleven dives into advanced searching in preparation for chapter twelve's information on reporting and (data) warehousing. Hierarchical queries are always challenging, so they're reserved for chapter thirteen. Finally, chapter fourteen is titled "Odds 'n' Ends" and is a general catch-all for some pretty advanced, but very infrequent problems.
I guess you either like the recipe approach or not. I love it, so I'm listing it as something to like about this book. The recipes are very well explained and while each one presents only one approach, where there are obviously multiple options, the discussion takes care to explain the reasoning behind the selection.
The writing is clear and the explanations are well laid out. Both the SQL code and the query results are presented well and are easy to read.
A very important part of the book is that it covers SQL variations for Oracle, IBM's DB2, Microsoft SQL Server and the open-source databases PostgresSQL and MySQL. Each of the recipes includes solutions for each of the five databases. While SQL is a standard, there seems to be some very relaxed definitions of full adherence to that standard; hence the book has to present up to five solutions for each problem.
Many of the recipes are advanced. While the front of the book has the entry level material, it ramps up in complexity pretty quickly. For some of us with very straightforward SQL knowledge, some of the recipes are going to take a while to fully understand and be able to use.
Many of the recipes are obviously oriented towards corporate reporting. If this is a big need for you, then this book goes along way to meeting your needs. If you have no need for corporate reporting, it's wasted paper.
This is an excellent book; it does exactly what it sets out to do and fully equips you to handle the most sophisticated database transactions.
You can purchase SQL Cookbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
The book is not for beginners and makes no efforts to teach any SQL. It concentrates purely on building on the base level of SQL knowledge that most programmers have. If you know the basics: Create, Read, Update and Delete (an unfortunate, yet memorable acronym) but rarely go beyond that, this book is for you. I know that I fall into this target market.
The point of the cookbook is that you need to get something done and you need to get it done sooner rather than later. Now, most of us can figure out most things given enough time, but in the real world, we rarely have enough time. The cookbooks objective is to save you time by giving you a successful approach that you could have figured out eventually anyway.
If you've previously read any other technology cookbook from O'Reilly, then you already know the structure of the recipes. For those new to the O'Reilly cookbook format, it's actually fairly straightforward. Each recipe starts out with a problem statement. Recipe one in chapter one, titled "Retrieving all Rows and Columns from a Table" has the problem statement "You have a table and want to see all of the data in it." Nice and clear. Then comes the solution. Naturally, for this problem statement we end up with a SELECT that looks like this:
select * from emp
Then the recipe has a discussion section where the solution is explained in more detail and the reasoning behind it is provided. For recipe one, the discussion explores the trade-offs between using the "*" to signify all columns versus naming each column explicitly.
The chapter structure through the book is very much one of building on the previous material. The first chapter starts with the fundamentals, the retrieving of records and then chapter two takes over with sorting the results of your query, while chapter three looks at using multiple tables.
Chapter four covers inserting, updating and deleting records. After that it's back into the world of queries, with chapter five exploring metadata queries for those times when you need to know just a little more about what's going on under the covers. Chapter six looks at working with Strings, a much harder topic than it would seem at first thought. Chapter seven addresses working with numbers and chapter eight does the same for date arithmetic with chapter nine bringing more understanding to general date manipulation. Chapter ten looks at working with ranges.
Chapter eleven dives into advanced searching in preparation for chapter twelve's information on reporting and (data) warehousing. Hierarchical queries are always challenging, so they're reserved for chapter thirteen. Finally, chapter fourteen is titled "Odds 'n' Ends" and is a general catch-all for some pretty advanced, but very infrequent problems.
I guess you either like the recipe approach or not. I love it, so I'm listing it as something to like about this book. The recipes are very well explained and while each one presents only one approach, where there are obviously multiple options, the discussion takes care to explain the reasoning behind the selection.
The writing is clear and the explanations are well laid out. Both the SQL code and the query results are presented well and are easy to read.
A very important part of the book is that it covers SQL variations for Oracle, IBM's DB2, Microsoft SQL Server and the open-source databases PostgresSQL and MySQL. Each of the recipes includes solutions for each of the five databases. While SQL is a standard, there seems to be some very relaxed definitions of full adherence to that standard; hence the book has to present up to five solutions for each problem.
Many of the recipes are advanced. While the front of the book has the entry level material, it ramps up in complexity pretty quickly. For some of us with very straightforward SQL knowledge, some of the recipes are going to take a while to fully understand and be able to use.
Many of the recipes are obviously oriented towards corporate reporting. If this is a big need for you, then this book goes along way to meeting your needs. If you have no need for corporate reporting, it's wasted paper.
This is an excellent book; it does exactly what it sets out to do and fully equips you to handle the most sophisticated database transactions.
You can purchase SQL Cookbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
As most people I know learn SQL and PHP together, if you're to the point that this book would be of benefit to you, I'd suggest also getting the PHP Cookbook. That book has done wonders on improving the quality of my code.
120 characters for a sig? That's bloody useless.
Shit, I've been calling it squirrel all this time!
"Da ist ein Technölüst in mein Unterpanten!"
You could pay $39 from BN, or $26.37 at Amazon.
This looks like a very handy reference for those of us who can read SQL statements alright, but have grown lazy with all the GUI SQL-statement builders that exist now.
A post a day keeps productivity at bay.
For those of you just starting out, try the the practical sql handbook. I recently glanced through edition 3. I started at edition one years ago. It still remains an awesome book.
I prefer the "u" in honour as it seems to be missing these days.
Indeed. I was always under the impression that "sequel" came from an old precursor to SQL called Structured English Query Language (Thus SEQL). Oh well, what do I know. I still call it S.Q.L. myself.
Dedicated Cthulhu Cultist since 4523 BC.
There are a few books by Joe Celko like SQL For Smarties that are in the position of honor on my bookshelf. If you're beyond "select * from emp" and want to really learn how to efficiently get things done in a relational database, Celko is your guy.
Ess-Cue-Ell. Yes indeedy. What about an Access Control List? Ayy-Cee-Ell or Ack-uhl?
SELECT eggs (*) AS ingredients
FROM Refrigerator
GROUP BY NO.dozen
INSERT INTO my_fryingpan (eggs1, butter1)
UPDATE my_table SET toast = 'lightly browned'
INSERT hole INTO toast
MERGE eggs INTO toast
USING (
SELECT Eggs, Toast)
CREATE Breakfast eggy_toast
DELETE FROM my_table WHERE plate = 'N'
He who knows best knows how little he knows. - Thomas Jefferson
Oh, and as to the OP stating that SQL is difficult, try IMS.
I'll take any SQL system over an IMS or other heirarchical anyday. :P I had the unfortunate need to learn IMS after years of various SQL databases. Sure it is faster, but what a learning curve!
The Kai's Semi-Updated Website Thingy
Second, I know plenty of mainframe and UNIX guys from way back who say "sequel" for SQL, some former IBMers, others not. The only people I ever hear call it "ess-que-ell" are management types and some FOSS people who have only ever heard about databases from reading stuff on the web and have never had a real job working with real databases.
One of the staples of corporate I.S. development is processing data, and increasingly these days that data lives in a relational database.
Thank you, Mr. Obvious!
Stop by my site where I write about ERP systems & more
As with the author of this review, I really like the cookbook format. I've made heavy use of the MySQL cookbook, also from O'Reilly, by Paul DuBois. It is excelent, and just about everything that Simon P. Chappell says about the SQL Cookbook applies, except of course the focus on just MySQL. I'm glad to hear of the SQL cookbook because I'll be developing for postgresql as well as MySQL in the near future. Thanks.
-- Mein Systemadminstrator hat einen großen schwarzen Moustache.
Select * From SovietRussia Where Article AND ReadsYOU
Check out my women's designer clothing store.
And the Microsofties are correct, if referring to the server platform. 'MS-SQL Server' is 'Microsoft Sequel Server.' (It's MS's product; they can call it whatever they wish.)
The structured query language is abbreviated 'ess cue ell.'
So it's perfectly correct to say, "let's see how that ess cue ell code performs on the sequel server."
If SQL is pronounced 'ess cue ell', is MySQL pronounced 'emm why ess cue ell'?
Chapter 11: Searching
40 pages, 500k PDF
Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
Yes, there's a great deal of nonconformance and extensions.
But, there is a standard, in fact, five: SQL-86, SQL-89, SQL-92, SQL:1999 and SQL:2003 (yeah, dashes replaced by colons, go figure). SQL:2003 can be purchased from ANSI or ISO, just like the C or C++ standards.
Various sites list product conformance to the standards.
When I write SQL, I pretty rigorously stick to SQL-99, as that's likely to be supported by most vendors. If I need to deviate from that, I make sure I know how to replicate the vendor-specific code in SQL-99 (e.g, postgresql's inherits keyword -- it's useful for sub-typing, but it can be effected by using joins and views).
If the non-standard code is DML (not DDL), I'll do my best to encapsulate it in a stored procedure or a view, and let the rest of my code call the encapsulated abstraction. This is just the same layering you'd do in any programming language to wall off platform-specific code. And just as you'd typedef in C or create abstract types in C++, you create UDTs in SQL too.
Here's an example, using a useful testing date "function" that is cross-dialect, doesn't rely on any user-supplied function support, and can be incorporated into live code.
(And yes, you can hire me.)
Opinions on the Twiddler2 hand-held keyboard?
I am not sure how anyone can resolve the following found in the review - emphasis mine.
How can a book not be for beginners when the first recipe teaches the most basic SQL command possible? I have this book and it is a very good book, but like most technical books it kills a great deal of trees needlessly to pad its count. You can probably rip more than 100 pages out of the book that is mindless beginner crap and self-flogging and actually have a very good technical reference for mid-level SQL people.
Programming: Its not just a job - its an indenture.
You could pay $39 from BN, or $26.37 at Amazon.
Yup, and I will, because Amazon sucks balls, what with their 1-click patents and "oh, by the way, all that stuff we promised before? Not so much!" privacy policies. Unlike some Slashdotters, I actually put my money where my mouth (or keyboard, if you prefer) is.
There is a series of official SQL Standards, but the trouble is nobody any longer measures the extent to which database vendors conform to the official standards. Once upon a time NIST used to do this, but that part of their work was cancelled after some lobbying by the big database vendors: naturally they much prefer it if you use their dialect then you get locked in to their product. Who allowed this to happen? I think it was Bill Clinton.
Structured Query Language is a misnomer, as it is not a complete language, just a small syntax, it is not limited to queries, and anybody who has used it will agree it's not structured.
For example, if you want to change data you use a different command to changing database structure.
SQL for smarties is the best advanced SQL book I've seen. Highly recommended for developers, and should be on the bookshelf of any DBA.
"Eye halve a spelling chequer, It came with my pea sea, It plainly marques four my revue, Miss steaks eye kin knot sea"