SQL: Visual QuickStart Guide 198
SQL: Visual QuickStart Guide | |
author | Chris Fehily |
pages | 424 |
publisher | Peachpit Press |
rating | 9/10 |
reviewer | objectboy |
ISBN | 0321118030 |
summary | A lucid SQL tutorial and professional reference |
What this book does right:
The myth that it's more important for a programming book to be technically accurate than well written endures even though the opposite situation is true: A lucid explanation of a difficult concept or clever algorithm is more valuable than a bug-free implementation of same.Consider Ken Henderson's The Guru's Guide to Transact-SQL , a book full of useful examples but so marred by the author's bloated style and disrespect for the language that I cringe every time I'm forced to read the text rather than simply lift a code snippet. Henderson even goes so far as to include an introductory section, titled "On Formality," about how he is going to split infinitives (even though their syntax is a burden for the brain to parse) and how he is going to use "data" in the singular sense (even though doing so can cause confusion) and how he considers "record," "row", and "tuple" to be interchangeable terms (even though they're not) and on and on. Readers would be aghast to find such self-exculpatory nonsense in the pages of Donald Knuth or Patrick Henry Winston. As for SQL: Visual QuickStart Guide, the author, a statistical programmer, presents each topic with a mathematician's sense of restraint and order. I've found few typos, no technical errors, and consistent use of technical terms.
Almost every aspect of SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP is covered. What distinguishes this book is that every ANSI SQL statement -- and there are hundreds of examples -- was tested on six separate DBMSes: Microsoft Access 2002, Microsoft SQL Server 2000, MySQL 4.0, PostgreSQL 7.1, Oracle 8i, and Oracle 9i (8i and 9i differ considerably in SQL-92 compliance). The examples in each section increase in depth and complexity, so you can stop reading once you've learned what you need to know. When an ANSI SQL statement doesn't work as-is on a particular DBMS, the author shows you how to fix it or offers workarounds (which is particularly useful for MySQL, whose adherence to the SQL standard is poor). These DBMS-specific fixes are given as separate "DBMS Tips" apart from the main body of text, so they don't interfere with the conceptual flow. This organization is especially useful for consultants who have difficulty keeping track of how each implementation deviates from the ANSI standard, and is superior to the alphabetical, segregated approach of O'Reilly's SQL in a Nutshell.
This book was shoehorned into the publisher's Visual QuickStart format, which, as I implied earlier, doesn't work well for procedural languages, but does work for a declarative language like SQL. A two-column layout separates examples from explanatory text. Red type highlights the relevant portions of code and results. The book is extensively cross-referenced and has an 18-page index. This layout also makes the book a good quick reference for experienced programmers. Almost all the examples use a single, sample database (so there's no need to memorize multiple schemas). The code listings and sample database are available for download.
The derivative nature of programming books makes it difficult to determine whether the author truly has mastered the material. Writing a book is a difficult task (perhaps even harder than programming) but, at the risk of exaggerating my point, I suspect that any determined, organized, and competent programmer could write any O'Reilly Nutshell book by paraphrasing existing materials. But if an author establishes his credentials early, the reader gains a sense of trust that remains throughout the entire book. In the introduction to this book, the author avoids an error that almost every other SQL-book author commits: that SQL stands for structured query language. According to ANSI (the only legitimate arbiter here), it stands for S-Q-L and nothing more. Fehily even offers an amusing explanation of why structured query language is the worst possible description of SQL. Throughout the book, the author also scatters bits of practical advice (job candidates are wise to say my-es-kyu-el, not my-sequel), beginner-friendly insights ("Although SELECT is powerful, it's not dangerous: You can't use it add, change, or delete data or database objects."), and advanced topics (optimization, concurrency control, logical data independence). It is these asides and respect for basic research, rather than swaths of expository text, that lend authority.
This book describes the effects of nulls in almost every aspect of SQL, including the interpretation of null-contaminated query results. You can no more be a competent SQL programmer without understanding nulls than you can be a competent LISP programmer without understanding recursion. Particularly useful are the discussion of three-value logic (true/false/unknown) and an algebraic derivation of how a null can cause a subquery to return an empty result unexpectedly (which has bitten me more than once).
As a wizened developer weary of hand-holding users and junior programmers through routine queries, I've found it mollifying to give away copies of this book (it's cheap) to reduce my interrupt stack.
What's Missing:
Some missing items that I would have found useful:- A glossary
- A quick syntax reference
- A chapter about statistics
- A chapter about advanced SQL "tricks"
- DB2 coverage
- Coverage of security commands (GRANT/REVOKE)
- An expanded query-optimization discussion
- Improved normalization examples
- A little more mathematical rigor in the set-theory discussion
You can purchase SQL: Visual QuickStart Guide from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Excuse me? (Score:1, Insightful)
So, you're saying... who cares if the code is wrong as long as you think you understand it? Personally, I'd rather have the right code.
Re:Excuse me? (Score:4, Insightful)
The two are equally important, and both are critical to a good technical book. You cannot have a good tecnical book that is poorly written. You simply cannot.
I remember the original X reference set from O'Reilly, and the whole reason that they were a success was that they were essentially duplicates of the online X documentation, which was some of the best written toolkit documentation, ever.
Had those been just as technically accurate, but even just a little harder to navigate and use, they would have been nearly useless, given the complexity of the topic.
You're better off (Score:2)
I prefer PL/SQL but my job uses T-SQL
Re:You're better off (Score:2)
Is there actually a standard for stored procs? I'd always assumed that Oracle had invented PL/SQL, then Sybase copied it into their own version. Sybase was then gutted by MickeySoft and made into SQL sorta follow standards but have a really nice gui Server.
Huh? (Score:2)
PL/SQL is the Oracle implementation of SQL
Stored procedures are independent of the language implentation, they just execute the SQL.
I like PL/SQL the best because I worked with Oracle extensively as my first Enterprise level database. Going from their implementation to the MS implementation was frustrating (for about a week, then it all sunk in, hell I'd probably be just as irritated if I had to go back to PL/SQL
Re:Huh? (Score:2)
PL/SQL is the Oracle implementation of SQL
I realize that. What they did tho is extend SQL to make stored procedures possible. The standard (SQL) offers nothing like the concept of variables and begin/end blocks. At least, not in the versions I've read. It's possible that it was added beyond SQL-99.
For what it's worth, I much prefer Oracle myself. At least sequences make sense and are easy to use. Try getting back the proper @@IDENTITY from Sybase/MSSQL a
Re:Huh? (Score:2)
Mal
Re:Huh? (Score:2)
I think your remark on frustrations is on the money. 80% of all programming languages are the same, the remainder being genuine feature differences and syntactic nuances.
Never did a whole lot in PL/SQL, though. The one or two non-trivial modules I did write seemed so close to the underlying C code (I'm pretty sure that's the source language) that y
Re:Huh? (Score:2)
My attempted point was that using packages like DBMS_SQL does little to hide the user from the underlying C implementation.
Never did any Java stuff on Oracle; I presume their JDBC stuff is more modern.
Re:Huh? (Score:2)
I guess getting a finance degree was worth it because I spend over 90% of my time in my companies doing finance related work and 10% actually developing (in maintenance mode right now, so I guess that is to b
Re:You're better off (Score:2)
Thanks for the info! Although I'm not too keen on DB2, so I guess I'll have to make due with not being compliant.
Re:You're better off (Score:2)
Wrong. Neither TransactSQL nor PL/SQL are implementations of SQL. Sybase and Oracle both implement SQL in fairly close compliance with the standard. In addition to providing SQL, they provide the procedural languages TransactSQL and PL/SQL, respectively.
Of course if you just want to be a "Sybase programmer" instead of a developer who understands databases, then go ahead and just study "the platform you will be using".
Re:Excuse me? (Score:2, Insightful)
Yet another programmer's reference (Score:1)
Mandatory Bookpool link (Score:5, Informative)
Bookpool [bookpool.com] has it for $14.50
Hmmm. (Score:1)
For those of you who use Linux or Mac OS X... (Score:3, Informative)
Linux and Mac OS X users, unite! Or untie. Or something...
Re:For those of you who use Linux or Mac OS X... (Score:2, Redundant)
Good question. I guess someone didn't like me and blew all their mod points. Just to tick them off I'll post it again.
Subject: For those of you who use Linux or Mac OS X...
Linux and Mac OS X users, unite! Or untie. Or something...
Re:For those of you who use Linux or Mac OS X... (Score:2)
Woop:For those of you who use Linux or Mac OS X... (Score:2)
Re:For those of you who use Linux or Mac OS X... (Score:2)
Re:For those of you who use Linux or Mac OS X... (Score:2)
Microsoft's marketting line is vulnerable to moderation
as a troll.
It looks to me as though they;re astroturfing m1 on slashdot.
Re:your sig is spelled wrong (Score:2)
Re:your sig is spelled wrong (Score:2)
Don't be rediculous. It's *supposed* to be nonsensical and silly.
Peachpit press is kinda useful. (Score:5, Interesting)
The books are cheap (twenty or thirty bucks) and small (easy to carry in a backpack). I think they're a really good value. Although, I wouldn't buy one for a more in-depth programming language, for the simpler stuff (html, xml) they're great.
Try the Codenotes series, too (Score:2, Interesting)
I have the XML [amazon.com] and the Web-Based UI [amazon.com] ones. They're both very handy to have around, and easier to carry than toting O'Reilly books everywhere. They also cover more ground
Re:Try the Codenotes series, too (Score:2)
What is the index like? (Score:4, Funny)
Re:What is the index like? (Score:3, Funny)
Don't you know that dictionary searchs are O(n) worst case!!!!???! If you have 10 million records, you could wait DAYS for your result! Use a hashtable index, or a B-Tree index. Your searches will go *much* faster.
Re:What is the index like? (Score:2)
Not all dictionary searchs are O(n) worst case! A binary search is a dictionary search (the list is in order) and a binary search is O(nlgn)* worst case.
* lg--log base 2
Correction! (Score:2)
Hate to reply to my own comment, but I said that wrong. A binary search is O(lgn) not O(nlgn).
Re:What is the index like? (Score:2)
It's a joke. Laugh. I thought about mentioning binary searches, but it just wouldn't be funny if I had to explain about going back and forth through the structure. Besides, the book uses lines with an abitrary location. Binary search only works if you know the location of every item.
I understand the convenience but... (Score:4, Insightful)
Re:I understand the convenience but... (Score:2)
Stored procedures used to be challenging, but (at least where I work) the DBAs are leaning towards cutting those out because they don't want to do the maintenance.
Aside from a pocket-book (it's a novel-sized SQL 92 reference), I don't keep too much SQL documentation around. Most of it is in my head, these da
Re:I understand the convenience but... (Score:2)
Enough to condense half of a corporate database down to one screenfull of information using only *one* select statement. That means case/switch statements, subslects, inner joins, outer joins, UNIONs, etc. Or maybe I'm too lazy to make more than one call to the database.
Re:I understand the convenience but... (Score:2)
DBAs? (Score:4, Insightful)
If you're a programmer, you need to know how to specify what you want to feed into a stored procedure, and what you want to get out of it. If you can't write the proc yourself, you need to get someone to write it for you. Embedded SQL is a bad idea. You tie yourself to one table structure because you can't possibly change all the embedded code snippets. You miss out on debugging opportunities because you won't use PRINT statements in your sql. Etcetera, etcetera, etcetera. I don't want to do maintenance on my code either, but it IS my job after all.
Re:DBAs? (Score:2)
Embedded SQL is a bad idea. You tie yourself to one table structure because you can't possibly change all
Re:DBAs? (Score:2)
On top of that having stored procedures out where a good DBA can get at them in a moments notice so they can search them for dependencies, see their table usage, and analyze indexes without having to sort through a bunch of application code written in a language they may not understan
Re:DBAs? (Score:4, Informative)
It's heresy where I'm working at right now. But that's only because the people who originally wrote the web-app f***ed things up by using ColdFusion for a complex business. CF offers you no good option for separating code, data, and SQL other than stored procs. Java on the other hand...
Would you want to recompile every line of app code before you execute it
SQL is not code. It does not compile down to any form of CPU instructions. It is a data structure designed to look like english. All "compiling" procedures does is pre-parse the query and do some statistical analysis that would otherwise be done at runtime. This is great for really complex queries. However, 90% of the queries in most systems are not seriously affected by "compiling".
On top of that having stored procedures out where a good DBA can get at them in a moments notice so they can search them for dependencies, see their table usage, and analyze indexes without having to sort through a bunch of application code written in a language they may not understand.
Having worked in an environment where we managed excellent performance without resorting to procedures, I can happily say that it comes down to your communication between your teams. If there is a rift between your DB people and your coders, you're going to have problems. Also, it helps a lot to get the database done right the first time. It really isn't too hard, but some DBAs seem insistent on denormalizing this for performance or doing this fun new winding data structure, or other weird crap instead of just *doing* it. Get the database done right and in production and worry about performance characteristics later. 99% of the time, you don't need to do anything about them anyway! (Beyond tweaking a few indexes that is.)
Re:DBAs? (Score:2)
Agreed on the compiling semantics. I use the term compile since that's the term my RDBMS uses even though it's not a true c
Re:DBAs? (Score:3, Interesting)
But a list of procs is way more difficult to manage than a Java API (for example). Procs have no concept of package structure and as a result, they all end up in one big jumble with 3 or 4 different styles of naming (to get around the problem) competing for your visual attention. Bandwidth internal to a network is nothing whe
Re:DBAs? (Score:2)
Just like anything else there is a right and a wrong way to do anything. If you have poor naming standards and don't organize your stored procs they'll be a hassle. If you don't structure your Java API's correctly you won't be a
I believe in separation of layers (Score:2)
I know web apps are the name of the game. At the e-commerce dot com I used to work at we used all embedded SQL and it was a huge mess as processes locked with each other when the engine had too many simultaneous requests and none of the direct sql that was used bothered to specify WITH (NOLOCK) on the 98% of the code that was just doing reads. Maintenance went way down when we moved to stored procedures that had locking spe
you can do it with tsql too (Score:2)
Re:DBAs? (Score:2)
Re:DBAs? (Score:2)
Re:DBAs? (Score:2)
That's the (well a major) whole point of a relational database management system. Your RDBMS is a series of axioms -- namely constraints -- a la business rules.
The problem with traditional three-tiered architectures is that they are a throwback to 'roll-your-own' DBMSs that plagued the industry in the 50s, 60s, and 70s. At least many of the 'business ru
Re:DBAs? (Score:2)
It's NOT 3-tier, its N-tier (Score:2)
Re:I understand the convenience but... (Score:2)
I just thanked God for my quiet little app development job, where the longest SQL query I've written has been about ten lines...
Then, I thanked him again, and again, and again...
Re:I understand the convenience but... (Score:2)
Re:I understand the convenience but... (Score:2)
May god have mercy on his soul.
i don't think so... (Score:2)
"SELECT DISTINCT tblCalender.CalenderID AS ID, tblActivity.Activity AS
ActivityType, tblCalender.ActivityDesc, tblProductFamily.ProductFamily,
tblProductCatego
possibly going to be 3? 7 fields and 7 values unless i'm crazy.
Re:i don't think so... (Score:2)
Three rows?
JP
Why not to use the vendor-specific documentation (Score:4, Insightful)
why would i use isnull? (Score:2)
coalesce (Score:2)
Re:I understand the convenience but... (Score:3, Insightful)
I agree at bottom with this statement. As a declarative, rather than procedural, language, for the basics SQL does not REALLY need a book.
However, just as in Perl, TMTOWTDI. And often several of those ways, depending on the RDBMS you are using, and, usually more importantly, on the data themselves, are FAR, FAR worse than many of the other ways. That's why you need a good book, both on the principles of SQL (I highly recomme
Re:I understand the convenience but... (Score:2)
Re:I understand the convenience but... (Score:4, Funny)
I have a set of DB2 manuals on my shelf, and can therefore answer your question with a confident "No".
SQLCourse (Score:5, Informative)
This is how I first cut my teeth in SQL, but I only developed 'real' skills when I started writing SAS code on a huge solaris system when I worked for a bank.
Re:SQLCourse (Score:3, Informative)
Before going hands-on, Philip Greenspun's SQL for Web Nerds [greenspun.com] offers a relatively speedy but deep overview.
mhm (Score:2, Informative)
Barnes and Noble has it for $21.99 while Amazon has it [amazon.com] for $15.39 (unless they have some kind of dinamic pricing and not everybody sees the same price).
Plus, there is also MySQL: Visual QuickStart Guide [amazon.com].
Good jumping off point... (Score:3, Insightful)
For beginners, this sounds like a good book to learn the basics of querying and allow them to begin honing their skills.
For professional (and soon-to-be professional) developers, learning STRONG SQL is a good idea. Many developers (esp. casual web devs) never take the time to get a good grasp on the language and write queries with a balance of effectiveness and efficiency.
Another good book to keep in mind (if you're serious about development) is "Database Design for Mere Mortals" by Hernandez and Getz. I'm sure it's been mentioned a few times here already.
SQL In A Nutshell (Score:2, Informative)
One thing I've become enamored of (Score:2)
SELECT -1 as Sort_key, count( ID ), ''
FROM tbl_some_table
UNION ALL
SELECT 0, ID, Name
FROM tbl_some_table
Your guaranteed to get something, if only a zero in the first row.
You make one trip to the database, a cheap, yet noticable performance boost.
You know exactly how many rows are in the result.
You aren't too platform-specific.
You can chain a truckload of these (keeping a weather eye on the Sort_key values).
Are there any arguments against this strategy, beyond the usual "tha
Re:One thing I've become enamored of (Score:2)
All it tells you is how many rows are in the particular table. The number of rows in the result is, of course, count( * ) + 1 since you have to account for the aggregate.
I assume you're doing something like (some weird pseudocode):
select * from table
put first row into rowcount
for( i = 1 to rowcount )
output 'row ' + i + ' of ' + rowcount
To the other guy who said it doubles query time that is
Re:One thing I've become enamored of (Score:2)
The primary target for the technique is something like a web page, where you have to get a bunch of <select> values which are not stable enough to simply cook into a script.
The exact amount of time increase is going to be situation-dependent. Clearly this is not something that should be done with every query, mainly lookup tables, or when you see real benefit from knowing in advance the number of rows for the result.
The problem with Peachpit Press books (Score:2, Informative)
Re:The problem with Peachpit Press books (Score:3, Insightful)
I teach Microsoft developer courses (MOCs). The materials are often plagued with similar issues that you find with "teach by example" systems. That's where I fill in the gaps using the whiteboard, demonstrations, online references
Re:The problem with Peachpit Press books (Score:3, Informative)
SQL:1999 (Score:2, Interesting)
SQL:1999 has been defined for years and some of the DBMSs have actually implemented some of its features. Yes, SQL:1999 is big and perhaps bloated in comparison with SQL-92, but it's not that bad if you concentrate on the core parts. Some of the news in SQL:1999 are actually clarifications on stuff in SQL-92.
SQL:2003 will probably be agreed on this year.
- So I find it strange to use the more than a decade old SQL-92 as the platform for a book published in the year 2002.
Another thing: I'd say it's "ISO
Re:Whaa? (Score:2)
You're executing a function, not a statement. Besides, that code only works on databases that have sequence structures (Oracle and PostgreSQL are the most popular) and only hurts something if done on a table that *must* be sequential. Like Invoice numbers. Kind of ticks off the feds if you're "missing" numbers.
Re:Whaa? (Score:2, Informative)
Also, SELECT * is widely overused, and in the wrong contect, can bring DB's/networks to their knees. It should be pointed out in that comment that you should always SELECT only the fields you need returned to you.
Of course, another evil SELECT is SELECT INTO, creating a temp table without explicitly doing so in your query.
I know :) Or Select INTO (Score:2)
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2, Informative)
Write me when the MySQL default syntax uses double-quotes for object names, single quotes for text, and drops that stupid backtick all together.
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
MySQL has been b
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Actually, I hate it because I develop for it [datadino.com]. The blasted thing is quirky as all hell and generally makes your life difficult. On the bright side, at least you don't have to insert a
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Well, at least I can help you [datadino.com] with that one. As for MySQL being quirky and annoying, I'm afraid magic is still out of my realm.
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:3, Interesting)
SQL92 says that if you multiply two numerics with a precision of say x and y digits to the right of the decimal place respectively, the result should have x+y digits of accuracy to the right of the decimal point.
i.e.
create table test (num1 numeric (10,2), num2 numeric(10,3));
insert into test valu
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
I can happily insert numbers that are too large or too small (and it just rounds up/down, respectively), numbers that are actually strings, dates which are not dates, and any combination of the above.
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
This is a vastly important point if you're maintaining a system o
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
I like the ANSI method because it clearly defines where the join conditions are.
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
How so? Joins are obvious in what they do, but quite wordy - by separating them out you can quickly scan the joins block to see which tables you are working with and it leaves the filters a lot less cluttered.
How does piling everything into the same place make it clearer and more maintainable?
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Re:I believe MySQL is SQL-92 compliant (mostly) (Score:2)
Re:Another thing left out... (Score:2)
Re:Another thing left out... (Score:2)
I don't use MySQL except for anything outside of LAMP, and even then, I try not to use it.
SQL Compliance comparison table (Score:2, Informative)
I'm not happy that this is required either but there you are.
Re:Nulls are annoying (Score:2)
2 things:
you can easily define all columns in all tables as NOT NULL. so if YOU don't want to use them, or consider tham a "poison pill" then don't allow them. But some of the rest of us might find a value in a NULLable column. For instance some rows, but not all in table A might have a relationsip to table B. Leaving a NULL value in that column (Foreign Key) pretty clearly expresses this concept.
Are you certain SQL was modeled on COBOL?? Granted I never used COBOL on the job, but what I recall of th
Re:Nulls are annoying (Score:2)
Re:Nulls are annoying (Score:2)
In a fully normalized schema you'd have what are essentially 'R-tables' (in Codd/Date speak) which represent one entity type.
So, you probably would have:
fname( PersonID, FirstName )
lname( PersonID, LastName )
etc.
Obviously storing a row with a PersonID with a null last name is redundant -- the lack of a row in lname is all you need (or actually don't need, as it were).
It's not clear (Score:2)
IBM developed a query language inspired by QUEL, which they jokingly named "sequel", rationalized as "Structure English (version of) QUEL".
That name was then shortened to SQL, still pronounced "sequel" by people who know what they're talking about, "ess queue ell" by people who don't.
So the name "SQL" was not really derived from "Structured Query Language"; rather, SQL was derived from SEQUEL, which was derived from Q
Re:SQL for Smarties (Score:2)
Re: (Score:2)
Re:how advanced does it get?? (Score:2)
Perhaps you should go to the book store and check it out. Currently, i am tutoring someone in SQL with that book.