Slashdot Mirror


SQL: Visual QuickStart Guide

objectboy writes with a review of Chris Fehily's SQL: Visual QuickStart Guide, writing "This book teaches ANSI SQL-92 programming to database beginners and intermediates. The publisher, Peachpit Press, publishes mostly end-user and novice titles that usually go unnoticed by professional programmers. Its Perl and PHP books, for example, are of little practical or tutorial use to an experienced developer. In fact, I noticed this SQL book only because a junior developer was using it for a course. The book's table of contents, index, and a sample chapter are posted on Amazon.com. The book's official web site contains errata and other information." Objectboy's review continues below. 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.

198 comments

  1. Excuse me? by Anonymous Coward · · Score: 1, Insightful

    "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"

    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.

    1. Re:Excuse me? by ajs · · Score: 3, Insightful

      I would agree with the text that you cited, right up until he talks about the opposite.

      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.

    2. Re:Excuse me? by vasqzr · · Score: 1


      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

      If it's well written, and you understand it, you'll have no problem fixing the errors in it, right?

      Unless you cut-n-paste.

    3. Re:Excuse me? by Anonymous Coward · · Score: 0

      Yes, yes, except that a novice will assume the example is correct and, therefore, that he or she hasn't properly understood the accompanying prose.

      That the book is well-written is the most important factor. That a book with incorrect examples is not well written is a matter of definition.

    4. Re:Excuse me? by Anonymous Coward · · Score: 0

      How do you learn syntax without proper examples? I can explain a while loop, but if I don't show you how to write one correctly, you can't correct it.

    5. Re:Excuse me? by mfifer · · Score: 1

      I'd rather *understand* a concept so *I* can go and write the *right* code myself.

      If it bugs you, it might help to think of the offending inaccuracies as pseudocode ;-)

    6. Re:Excuse me? by mrmez · · Score: 2, Insightful

      Yes, it's more important to understand the language than to have good, solid code examples which I can't actually use because either they don't do what I need to do or I just can't understand them well enough to implement them where I need them. It's also more important to be able to write the best code for the job than to be able to grab some inefficient code which allows me to work around its inadequacies for my specific usage so that I can just about do what needs to be done. I choose comprehension over examples.

  2. SQL for Smarties by Anonymous Coward · · Score: 0

    Is the only SQL book worth reading. Period.

    1. Re:SQL for Smarties by Anonymous Coward · · Score: 0

      Best advice in this whole thread...

      I learned more from that book than any other SQL books I've ever read.

    2. Re:SQL for Smarties by PizzaFace · · Score: 1
      Maybe it's the only book worth reading for an experienced SQL programmer, but SQL for Smarties is not for SQL beginners. These are the first words of the Introduction:

      This book, like the first edition, is for the working SQL programmer who wants to pick up some advanced programming tips and techniques. It assumes that the reader is an SQL programmer with a year of actual experience.

  3. Yet another programmer's reference by dook43 · · Score: 1

    book that I won't be purchasing; I already have 5 or so $50 books that are currently serving as expensive doorstops. Anything you can get out of these books can easily be grokked or googled for through the web. -

    --
    This comment was randomly generated by a school of piranhas chewing on the PCB of a Microsoft Natural Keyboard.
    1. Re:Yet another programmer's reference by vasqzr · · Score: 1


      These books from Peachpit are usually $12-$20, so you're not spending $50 on a book. Very worth it.

      There's a ton of info on the web, but most people learn the basics better from a book. You can always borrow books from friends and buy used to save $$$. Or, get your job to reimburse you.

  4. Mandatory Bookpool link by vasqzr · · Score: 5, Informative


    Bookpool has it for $14.50

    1. Re:Mandatory Bookpool link by duncanatlk · · Score: 1

      Not any more they don't. Out of stock = slashdotted.

    2. Re:Mandatory Bookpool link by Anonymous Coward · · Score: 0

      Nerd Books has it for $13.85
      http://www.nerdbooks.com/item.php?id=03211 18030&PH PSESSID=14303549aa4964e7058b490919697644

  5. Hmmm. by radiumhahn · · Score: 1

    I like to keep beginner books around for reference. I think I'll keep my C J Date book on SQL. It has yet to let me down.

  6. For those of you who use Linux or Mac OS X... by AKAImBatman · · Score: 3, Informative

    ...make sure you pick up a cross-platform tool for working with SQL. SQL Server is particularily hard to use in a cross-platform way, but thanks to the jTDS and FreeTDS projects, we now have drivers.

    Linux and Mac OS X users, unite! Or untie. Or something...

    1. Re:For those of you who use Linux or Mac OS X... by AKAImBatman · · Score: 1, Redundant

      > Why is this a troll?

      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...
      ...make sure you pick up a cross-platform tool for working with SQL. SQL Server is particularily hard to use in a cross-platform way, but thanks to the jTDS and FreeTDS projects, we now have drivers.

      Linux and Mac OS X users, unite! Or untie. Or something...

    2. Re:For those of you who use Linux or Mac OS X... by mal3 · · Score: 1

      Probably because you're blatantly hocking the product of the company you work for/own under a story that is only vaguely related to the story. Essentially it's the same as trying to sell spam blocking software in one of the many stories about spam.

      --
      Non gratis rodentus anus
    3. Re:For those of you who use Linux or Mac OS X... by AKAImBatman · · Score: 1

      That's certainly a valid reason to mod me down, but it's hardly a reason to mod me as a Troll. Or mod me down *twice* as a troll. There's a wonderful option for "offtopic" if that's what you want to do. :-)

    4. Re:For those of you who use Linux or Mac OS X... by aminorex · · Score: 1

      I find that any post that I make which is contrary to
      Microsoft's marketting line is vulnerable to moderation
      as a troll.

      It looks to me as though they;re astroturfing m1 on slashdot.

      --
      -I like my women like I like my tea: green-
    5. Re:For those of you who use Linux or Mac OS X... by Anonymous Coward · · Score: 0

      cause everyone knows if your running linux or os x you should just install postgresql :-)

  7. Peachpit press is kinda useful. by crazyphilman · · Score: 4, Interesting

    I liked their javascript and XML quickstart guides; they're basically ways of getting up to speed on something really quickly, and for relatively simple subjects (like Javascript, html, and xml) they might be all you need outside of web searches. The xml book had some really nice info about stylesheets and XSLT, for instance, and I use the stylesheet reference even when I'm just doing some HTML.

    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.

    --
    Farewell! It's been a fine buncha years!
  8. What is the index like? by danormsby · · Score: 4, Funny

    If an SQL book isn't easy to search I'm not buying it.

    --
    Omnis amans amens
    1. Re:What is the index like? by needamiracle · · Score: 0

      Pretty funny...

    2. Re:What is the index like? by Anonymous Coward · · Score: 0

      i believe there's this newfangled concept called "alphabetical order" that may help you navigate and search the index.

    3. Re:What is the index like? by AKAImBatman · · Score: 2, Funny

      i believe there's this newfangled concept called "alphabetical order" that may help you navigate and search the index.

      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.

    4. Re:What is the index like? by quasi_steller · · Score: 1

      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

      --
      ...interesting if true.
    5. Re:What is the index like? by tarquin_fim_bim · · Score: 1

      Are you saying you would end the transaction with a rollback? Cheapskate.

    6. Re:What is the index like? by AKAImBatman · · Score: 1

      Not all dictionary searchs are O(n) worst case!

      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. ;-)

  9. I understand the convenience but... by dhodell · · Score: 4, Insightful

    ... doesn't it end up being easier reading the documentation for the SQL products themselves? SQL is one of the few languages I would argue actually does *not* need a book. Reading a PHP/Perl book about any RDBMS using SQL would enlighten one as to the basic functionality; all further research could be done on the site of the RDBMS of choice. Yes, this would imply that they end up learning implementation specific SQL, but as long as one sticks to the "basic guidelines" found in the aforementioned books, one should be able to write fairly portable SQL, and fairly quickly.

    --
    Kind regards, Devon H. O'Dell
    1. Re:I understand the convenience but... by crazyphilman · · Score: 1

      If you're a programmer, how much SQL do you need, anyway? You have to know inserts, selects, updates, deletes, and transactions, right? Maybe subqueries, but that's more of an art than anything else...

      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 days...

      --
      Farewell! It's been a fine buncha years!
    2. Re:I understand the convenience but... by dhodell · · Score: 1

      Well here's an example of a nice SQL thing that I got in the email from a sysadmin friend of mine. Feel free to mod this as "Funny" -- it doesn't fit anything else... I feel sorry for this dude.

      --
      Kind regards, Devon H. O'Dell
    3. Re:I understand the convenience but... by AKAImBatman · · Score: 1

      > If you're a programmer, how much SQL do you need, anyway?

      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. ;-)

    4. Re:I understand the convenience but... by Anonymous Coward · · Score: 0

      For those of us who can't run the code in our heads, want to explain the humor?

    5. Re:I understand the convenience but... by jpetts · · Score: 2, Insightful

      SQL is one of the few languages I would argue actually does *not* need a book.

      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 recommend Joe Celko's SQL For Smarties), and an RDBMS-specific book as well. I use Oracle, and my recommendations in this area are Mastering Oracle SQL by Mishra and Beaulieu, and the Oracle SQL Tuning Pocket Reference by Mark Gurry.

      --
      Call me old fashioned, but I like a dump to be as memorable as it is devastating - Bender
    6. Re:I understand the convenience but... by Anonymous Coward · · Score: 0

      The answer is "3".

    7. Re:I understand the convenience but... by Anonymous Coward · · Score: 0

      Translation: "Oh look at me! I know SQL like the back of my hand therefore I don't need a beginner's book therefore anyone who does is just stupid."

      We all had to learn from first principles once. I spent weeks looking at examples and documentation and trying to get the hang of it. I ended up buying a SAMS Teach Yourself in 24 Hours book and learned everything I needed to know (plus a bit more for good measure) in no time. Specialised books have a way of filling in the important little gaps in knowledge and building up a complete picture in a structured manner that no ad-hoc messing around or non-specialised books can ever do.

    8. Re:I understand the convenience but... by Malc · · Score: 1

      I needed books. At university, I found relational algebra easier than SQL - it was taught as a formal introduction to SQL in DBMS course I took. However, I never really grasped SQL until later on when I had to work with it. The online documentation serves me as a reference now, but it took books with lots of esoteric examples (thanks Joe Celko) to help me get over the initial hump, and develop deeper insight. It's not just me - I've noticed other people who just can't get their brain working/thinking in the right way to deal with things in this set-based manner. Probably too much time thinking along structural or OO lines. Maybe more time on LISP would have helped ;)

    9. Re:I understand the convenience but... by metamatic · · Score: 3, Funny

      ...doesn't it end up being easier reading the documentation for the SQL products themselves?

      I have a set of DB2 manuals on my shelf, and can therefore answer your question with a confident "No".

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    10. Re:I understand the convenience but... by crazyphilman · · Score: 1

      Good heavens...

      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... :)

      --
      Farewell! It's been a fine buncha years!
    11. Re:I understand the convenience but... by crazyphilman · · Score: 1

      Yeesh! In your free time, do you do extreme sports, by any chance?

      --
      Farewell! It's been a fine buncha years!
    12. Re:I understand the convenience but... by EastCoastSurfer · · Score: 1

      That query really isn't too bad. It is just formatted poorly. If I took some of my MSSQL querys that generate XML output and took most of the spacing they would look frightening too. Even though they are actually fairly simple with just a lot of text.

    13. Re:I understand the convenience but... by glitch_ · · Score: 1

      The worst part is that is an ACCESS QUERY!!!!
      May god have mercy on his soul.

  10. SQLCourse by Jucius+Maximus · · Score: 4, Informative
    If you just need an intro level starter to SQL and you've never even written a query before, you can't do much better than the free tutorials at SQLCourse.com. As long as you're generally adept at using computers and it doesn't scare you to learn a new language, it will definitely give you a good start.

    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.

    1. Re:SQLCourse by ryantate · · Score: 2, Informative

      I found SQLZoo.net an extremeley useful tutorial. One of the cool things is you can pick the SQL engine used for the exercises, including MySQL, Postgres, Oracle and SQLServer.

      Before going hands-on, Philip Greenspun's SQL for Web Nerds offers a relatively speedy but deep overview.

    2. Re:SQLCourse by oscarcar · · Score: 1

      Mod parent up. That's a pretty cool site.

      A worthy bookmark if you deal with SQL at all.

  11. $6.60 = 30% CHEAPER AT AMAZON!! by Anonymous Coward · · Score: 0
  12. Whaa? by wren337 · · Score: 1
    "Although SELECT is powerful, it's not dangerous: You can't use it add, change, or delete data or database objects."

    What about "SELECT MYSEQUENCE.NEXTVAL FROM DUAL" ?

    1. Re:Whaa? by AKAImBatman · · Score: 1

      > What about "SELECT MYSEQUENCE.NEXTVAL FROM DUAL" ?

      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.

    2. Re:Whaa? by at_kernel_99 · · Score: 1

      Thats just Oracle, baby. Not ANSI standard SQL.

    3. Re:Whaa? by I8TheWorm · · Score: 2, Informative

      Yeah, you could run my company out of employee id's fairly quickly that way.

      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.

      --
      Saying Android is a family of phones is akin to saying Linux is a family of PCs.
    4. Re:Whaa? by Anonymous Coward · · Score: 0

      What about

      select * from table1, table2

      That one can be really dangerous, just ask my boss!

    5. Re:Whaa? by Anonymous Coward · · Score: 0

      And really useful when generating time series. Not all cartesian products are ipso facto badthink.

    6. Re:Whaa? by wren337 · · Score: 1

      Sure, it's a function, yes, it's not standard.

      But the statement that executing SELECT never has any side effects is just wrong.

    7. Re:Whaa? by I8TheWorm · · Score: 1

      You'd be amazed at the damage done by cartesian products.. or rather, where they come from. We have an ASP that provides us with data from a proprietary source, and they (data experts) were guilty of a cart.prod about a week ago.

      --
      Saying Android is a family of phones is akin to saying Linux is a family of PCs.
    8. Re:Whaa? by FreeBSDbigot · · Score: 1

      Gotta agree with you on that one -- as an Oracle DBA, I've found many a developer's SELECT to be dangerous to my own reputation. Not just cartesian products, either.

      By the way, it's refreshing to read a /. review that's actually well-conceived, well-researched, and well-written.

      --
      Orange whip? Orange whip? Three orange whips.
    9. Re:Whaa? by Bigboote66 · · Score: 1

      and only hurts something if done on a table that *must* be sequential

      If your data must be sequential, you better not use a sequence. Even if you reduce the bucket size to 1 (which is necessary to prevent gaps occuring for all sorts of reasons, such as system restarts or even a large amount of procedure recompilation), you'll still get gaps if you have transactions that roll back. Probably the only reliable way is to exclusive lock the table in question, insert max(id) + 1, and don't release the lock until you commit or rollback.

      -BbT

  13. Is that knowledge in your pocket...? by Anonymous Coward · · Score: 0

    " book that I won't be purchasing; I already have 5 or so $50 books that are currently serving as expensive doorstops. Anything you can get out of these books can easily be grokked or googled for through the web. -"

    Scan them all, and do some OCR. Put them in this format on a DVD, and they can be carried were ever they're needed.

  14. I believe MySQL is SQL-92 compliant (mostly) by akiaki007 · · Score: 0, Informative

    It's mostly complient to 92, and working towards 99. Check here for it's current "Bugs" status.

    The only noted "bug" in it's SQL-92 complience is that whitespace gets stripped out at the end of VARCHAR types. Though a bug, there are other databases that do this as well. MySQL is working on becoming SQL-99 complient and have already started to look at (hypothetically) the changes that are to be made for SQL-2003 compliance.

    --
    "Time is long and life is short, so begin to live while you still can." -EV
    1. Re:I believe MySQL is SQL-92 compliant (mostly) by stratjakt · · Score: 1

      whitespace is supposed to be stripped from varchar, but not from char.

      Ie, "hello" in a varcharI10) = "hello", in a char(10) = "hello "

      But whatever, who cares.

      MySQLs lack of subselect support (its there but not in production code) make it utterly useless to the company I work for.

      --
      I don't need no instructions to know how to rock!!!!
    2. Re:I believe MySQL is SQL-92 compliant (mostly) by AKAImBatman · · Score: 1, Informative

      *cough* *cough* bullshit *cough* *cough*

      Write me when the MySQL default syntax uses double-quotes for object names, single quotes for text, and drops that stupid backtick all together.

    3. Re:I believe MySQL is SQL-92 compliant (mostly) by Anonymous Coward · · Score: 0

      Take a look at this table for some info on standards compliance.

      MySQL is not on the table but I suspect that it would fail terribly.

    4. Re:I believe MySQL is SQL-92 compliant (mostly) by PaschalNee · · Score: 1

      From the doc you reference

      1.8.1 What Standards Does MySQL Follow?
      Entry-level SQL-92

      where 'Entry-level' presumably means not very good.

    5. Re:I believe MySQL is SQL-92 compliant (mostly) by AKAImBatman · · Score: 1

      Seems someone around here is a MySQL fan. Modded parent up, and all the replies down. Hmm... Maybe it's time to introduce Slashdot to a real database?

    6. Re:I believe MySQL is SQL-92 compliant (mostly) by akiaki007 · · Score: 1

      4.1 (and I think 4.1) have subselect support, so check out the later versions.

      --
      "Time is long and life is short, so begin to live while you still can." -EV
    7. Re:I believe MySQL is SQL-92 compliant (mostly) by stratjakt · · Score: 1

      Well, what I said is its still not working in a production release.

      I cant ship solutions to clients that have major components labelled "beta" or "release candidate", even if it's bug-free and rock solid.

      I've played with them though, as it stands subselect support is horrendously slow, at least in my tests. I probably have to rebuild it with a bunch of options and other database types to get it to work.

      --
      I don't need no instructions to know how to rock!!!!
    8. Re:I believe MySQL is SQL-92 compliant (mostly) by akiaki007 · · Score: 1

      well, after 2 posts to my parent post, clearly you're the opposite of me ;) Yes, I'm a MySQL fan. BTW, postgresql is also good. They both have their advantages and such. You are more than welcome to use single-quote in MySQL. I don't know about using double-quotes for object names (if it works) since I haven't tried using the newer version of MySQL, but I do know that the 4.x branch has vast improvements over the 3.x branch. It supports transactions, subqueries and all that wonderful stuff.

      MySQL has been bashed a lot, but that's probably because people stopped using it in favor of a pirated version of oracle or sql server or whatever (postgresql), but it has made quite a few large improvements in the recent months/years and I bet most of the MySQL bashers could give it another shot and then not complain anymore.

      --
      "Time is long and life is short, so begin to live while you still can." -EV
    9. Re:I believe MySQL is SQL-92 compliant (mostly) by stratjakt · · Score: 1

      I use SQL Server all day at work.

      At home, I have a database driven archiving app that I use MySQL on.

      If I had spare cash to buy my own SQL Server license, I would in a heartbeat.

      MySQL is "coming along", sure, but is really not much better than when I was first exposed to it over a half a decade ago.

      Even forgiving its syntaxes and behavioral quirks, life sucks without Query Analyser and Enterprise Manager and other GUI based data manipulation tools.

      --
      I don't need no instructions to know how to rock!!!!
    10. Re:I believe MySQL is SQL-92 compliant (mostly) by AKAImBatman · · Score: 1

      MySQL has been bashed a lot, but that's probably because people stopped using it in favor of a pirated version of oracle or sql server or whatever (postgresql), but it has made quite a few large improvements in the recent months/years and I bet most of the MySQL bashers could give it another shot and then not complain anymore.

      Actually, I hate it because I develop for it. 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 '0' in an autonumber field anymore...

    11. Re:I believe MySQL is SQL-92 compliant (mostly) by AKAImBatman · · Score: 1

      Even forgiving its syntaxes and behavioral quirks, life sucks without Query Analyser and Enterprise Manager and other GUI based data manipulation tools.

      Well, at least I can help you with that one. As for MySQL being quirky and annoying, I'm afraid magic is still out of my realm. :)

    12. Re:I believe MySQL is SQL-92 compliant (mostly) by glenstar · · Score: 1

      DataDino is nicely done! I just did the webstart and was pretty impressed. Nice job.

    13. Re:I believe MySQL is SQL-92 compliant (mostly) by Sxooter · · Score: 2, Interesting

      MySQL is so full of little incompatibilities with SQL92 it's not even funny. Here's one (of about a hundred examples you can come up with if you scour the SQL92 spec and compare what it says to what MySQL does.)

      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 values (4.54,8.679);
      select num1*num2 from test;

      you get 39.403 for an answer. You're supposed to get 39.40266 for an answer, but MySQL just chops off the extra digits, in clear violation of the SQL92 standard.

      Because of this, it's unlikely MySQL will be used by anyone (with a brain and capable of testing MySQL for compliance anyway) in a financial application like Oracle or Postgresql would be suited for.

      There are plenty of other issues with MySQL. Anyone who's used databases a lot before seeing MySQL just shakes their head and laughs at the idea that someone would use it to store critical data.

      --

      --- It is not the things we do which we regret the most, but the things which we don't do.
    14. Re:I believe MySQL is SQL-92 compliant (mostly) by cruachan · · Score: 1

      Yeah, but I've never been convinced that SQL-92 was a move forward anyway. IMHO although the concept of separating join logic from filter (where) logic makes academic sense, in practice it's extreamly difficult to write down complex SQL involving multiple tables in a way that's easy to read and comprehend. In contrast if you do everything in the where statements then if you order and indent correctly it's much easier to see what's going on.

      This is a vastly important point if you're maintaining a system of any complexity over any period of time. I'm aware that the older syntax can be ambigous in some circumstances, but again in practice the instances where this is a problem are vastly outweighed by the maintenance issues.

    15. Re:I believe MySQL is SQL-92 compliant (mostly) by Sxooter · · Score: 1

      Actually, the majority of Databases that claim SQL-92 compliance only claim entry level compliance.

      --

      --- It is not the things we do which we regret the most, but the things which we don't do.
    16. Re:I believe MySQL is SQL-92 compliant (mostly) by MattRog · · Score: 1

      I've generally found quite the opposite in trying to teach complicated joins to people. I can understand it both ways, but the newbies generally don't like the mashing of everything together in the where clause.

      I like the ANSI method because it clearly defines where the join conditions are.

      --

      Thanks,
      --
      Matt
    17. Re:I believe MySQL is SQL-92 compliant (mostly) by AKAImBatman · · Score: 1

      Thank you. :-)

    18. Re:I believe MySQL is SQL-92 compliant (mostly) by glwtta · · Score: 1
      in practice it's extreamly difficult to write down complex SQL involving multiple tables in a way that's easy to read and comprehend

      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?

      --
      sic transit gloria mundi
    19. Re:I believe MySQL is SQL-92 compliant (mostly) by MattRog · · Score: 1

      That, and there is virtually NO domain (aka type) checking at all.

      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.

      --

      Thanks,
      --
      Matt
    20. Re:I believe MySQL is SQL-92 compliant (mostly) by laurat · · Score: 1

      See
      http://www.mysql.com/events/uc2003/session.ht ml
      about 3/4 of the way down the page for a analysis of MySQl vs the ANSI standards. (There was a more up to date version of this talk given at OSCON and I'm sure you could ask Peter for a copy.)

  15. Back when it was SQL-Eighty Something by Anonymous Coward · · Score: 0

    I still can't believe we need a chapter on all the implementation differences. SQL-XX compliance seems to be as worthless a label as it was over ten years ago.

  16. mhm by edmz · · Score: 2, Informative

    Barnes and Noble has it for $21.99 while Amazon has it 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.

    1. Re:mhm by Anonymous Coward · · Score: 0

      unless they have some kind of dinamic pricing

      Or the prices were blown up with dinamite.

  17. how advanced does it get?? by at_kernel_99 · · Score: 1

    It is difficult to determine, from the sample pages at Amazon, how advanced this book gets. I'm looking for a book that covers SQL 92 joins. Particularly the nuances of outer joins, exists statements and the like. We need a good SQL reference in the office that will show newbies the SQL92 way.

    Anyone know of such a text?

    1. Re:how advanced does it get?? by Chacham · · Score: 1

      Well "Understanding SQL" by Martin Gruber is an excellent book. He updated it with Mastering SQL, but started the other way around (DDL before DML) so i didn't bother with it.

      Perhaps you should go to the book store and check it out. Currently, i am tutoring someone in SQL with that book.

  18. Another thing left out... by nacturation · · Score: 0, Redundant

    One thing I was especially hoping to see in this book is the topic of Advanced Transactional Support in MySQL.

    --
    Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    1. Re:Another thing left out... by stratjakt · · Score: 1

      Haha

      Yeah and a chapter on subselects and triggers for MySQL would be nice too.

      --
      I don't need no instructions to know how to rock!!!!
    2. Re:Another thing left out... by AKAImBatman · · Score: 1

      That would be because transactional support doesn't exist in MySQL. Actually, that's not entirely true. Transactions were added to MySQL 4.0 and are a very new thing. Whether they work or not, how well they work, etc, etc, etc is still up in the air.

    3. Re:Another thing left out... by paitre · · Score: 1

      Why would a book covering a the SQL -standard- go into implementation specific things with MySQL that either aren't standard compliant, or were added after the book was written?

      I don't use MySQL except for anything outside of LAMP, and even then, I try not to use it.

    4. Re:Another thing left out... by Anonymous Coward · · Score: 0

      That's mentioned very briefly in the chapter covering MySQL stored procedures.

    5. Re:Another thing left out... by laurat · · Score: 1

      Actually it's had transactions since 3.23. 4.1 has subqueries and they work nicely.

  19. Try the Codenotes series, too by Wee · · Score: 2, Interesting
    I don't have any Peachpit books, but if you like small form factor, backpack-sized references try the Codenotes series of books. They're really small (roughly 5x8 inches), and get right to the point. They're very good references when you can't get to online sources. You need to have some passing familiarity with the material, however.

    I have the XML and the Web-Based UI ones. They're both very handy to have around, and easier to carry than toting O'Reilly books everywhere. They also cover more ground than the O'Reilly "Pocket Reference" series tend to.

    -B

    --

    Ash and Hickory, straight-grained and true, make excellent bludgeons, dandy for the cudgeling of vegetarians.

    1. Re:Try the Codenotes series, too by crazyphilman · · Score: 1

      Yeah -- codenotes are cool. I've got the XML one at home. They make a nice Java one, too. Awesome set of books...

      --
      Farewell! It's been a fine buncha years!
  20. Why not to use the vendor-specific documentation by brlewis · · Score: 3, Insightful

    If you read Oracle's docs, they'll tell you to use NVL(). If you read MSFT's docs, they'll tell you to use ISNULL(). Both databases support the standard SQL function COALESCE() that does the same thing and is portable. There are other similar examples. Only use the docs that came with your database if your database is PostgreSQL. Except for backslashes within string literals, they pretty much respect the standard.

  21. Re:I believe MySQL is SQL-92 compliant (troll?) by Anonymous Coward · · Score: 0
    Surely the parent should have been modded 'troll' instead of 'informative'.

    MySQL's frequently bashed for being bad and/or slow at SQL standards support (subqueries, a redefined concatenation operator, handling floating point math incorreclty, etc)

    How'd that post get "informative"?!?

  22. You're better off by BoomerSooner · · Score: 1

    You're better off buying a book targeted toward the platform you will be using. TransactSQL and PL/SQL have very different implementations of the same "standard". If you're using MySql or postgres just get some of their excellent manuals.

    I prefer PL/SQL but my job uses T-SQL :( I guess that's why I get paid, doing what the bosses want.

    1. Re:You're better off by AKAImBatman · · Score: 1

      TransactSQL and PL/SQL have very different implementations of the same "standard".

      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.

    2. Re:You're better off by njdj · · Score: 1

      TransactSQL and PL/SQL have very different implementations of the same "standard"

      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".

    3. Re:You're better off by Anonymous Coward · · Score: 0
      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.

      There is. It's called SQL/PSM and was first released as part of SQL 99. It's an amalgamation of pl/sql and transact-sql .. since DB2 was the last to implement a procedural sql language, and waited for it to be standardized, it is most compatible with the standard. Not that it is worth much unless the other vendors eventually comply as well.

    4. Re:You're better off by AKAImBatman · · Score: 1

      There is. It's called SQL/PSM and was first released as part of SQL 99.

      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.

  23. SQL Compliance comparison table by 3770 · · Score: 2, Informative

    Here's a table that summarizes the standards compliance for a few database systems.

    I'm not happy that this is required either but there you are.

    --
    The Internet is full. Go Away!!!
    1. Re:SQL Compliance comparison table by Anonymous Coward · · Score: 0

      This table is blantly wrong in many areas. (Want some examples? I used TRIM the other day in SQL 2000. One example is enough - go find your own.)

  24. One thing .... by frodo+from+middle+ea · · Score: 1
    From my experience of learning of SQL, I have come to the conclusion that you really don't master SQL unless you face a unique problem.
    After you have learnt the logical basics, like joins, predicates, etc and the physical basics like partitions, etc etc. You are preety much set for basic SQL stuff.

    At this point even if you read about advanced sorting, joining, complex inner queries , outer joins etc, you tend to forget them if they are not a solution to your immediate problems.

    Once to get donw to the real Coding, and face challanging tasks which require complex queires, only then can you learn and remember the complex SQL stuff.

    --
    for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
    1. Re:One thing .... by CausticPuppy · · Score: 1

      I really learned some great SQL tricks when I had to query against a completely retarded data model that I had no control over.

      During this time I came up with something called a "coincidental join." That's where you select rows from a set of tables that contain values that just so happen to meet criteria that are defined based on values in other tables (in other words, having to join on a calculation, because the WHERE clause is effectively different for each record).
      Sure, I could've done it much better using P-SQL... did I mention that the client insisted that the reports be done with Microsoft Access (attached to oracle tables) and wouldn't allow me DB access to write proper stored procedures?

      The woman who wrote the requirements for the reports I had to do was the same woman that created the data model. I asked her if we could create a new index on some particular fields and she responded "what's an index?" Yes, this is exactly the type of person that should be dictating the tools that are used and designing the data model.

      So, a challenging data model is the best way to accidentally write a sentient query.

      --
      -CausticPuppy "Of all the people I know, you're certainly one of them." -Somebody I don't know
  25. Nulls are annoying by Tablizer · · Score: 1

    Many relational gurus suggest that nulls can and should be tossed from relational languages. "3-value logic" is far messier than Boolean logic (2-value). I personally think nulls are okay for numbers, but NOT for Booleans and strings. In strings, nulls are like a "poison pill" in which one null value can ruin the entire result.

    I also think SQL should be replaced by some other relational language, but it is too entrenched right now. Relational languages could be a lot simpler IMO without losing power. SQL was sort of modeled on COBOL, which tries to be "English-like", complicating the language and the structure.

    1. Re:Nulls are annoying by at_kernel_99 · · 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 the language doesn't much remind me of SQL.

    2. Re:Nulls are annoying by MattRog · · Score: 1

      The only reason why nulls are 'needed' is because the tables are not fully normalized. If you fully normalize your table the lack of a relationship is clear -- there is no row that matches parent = 123, fk = 456.

      --

      Thanks,
      --
      Matt
    3. Re:Nulls are annoying by Tablizer · · Score: 1

      Even if they weren't normalized, one could still use say "0" or "-1" to represent empty keys.

    4. Re:Nulls are annoying by dcam · · Score: 1

      Um no.

      NULL is a placeholder. It means that you don't know the value. It is perfectly valid when a table is fully normalised.

      NULL is a perfectly valid value when you literally don't know the value for a column. The choice at that point is whether to use NULL or another, user (user being you) specified, value.

      NULLs being returned in a resultset are valid when used in an OUTER JOIN, which is the situation you are talking about. In this case the relationship between the two tables might be 0 or *, ie can join 0 or an infinite number of rows.

      This is *not* a normalisation failure.

      --
      meh
    5. Re:Nulls are annoying by dcam · · Score: 1

      Really. COALESCE a bit to hard to follow?

      What about OUTER JOINS?

      What else are you going to use as a placeholder?

      Which relational gurus (links please)?

      --
      meh
    6. Re:Nulls are annoying by MattRog · · Score: 1

      A fully normalized table consists of nothing but a key-value pair. A key with a null value is meaningless, hence the lack of a row.

      There is a huge difference in storing nulls and deriving (the outer join) nulls.

      Now, I will say that current SQL DBMSs ensure that the null is almost required to obtain optimal performance.

      However, given a truely relational DBMS, nulls wouldn't even be in the picture.

      --

      Thanks,
      --
      Matt
    7. Re:Nulls are annoying by wolja · · Score: 1

      In the SQL I have used, Oracle, Sybase , Progress to name a few a null ruins number arithmetic just as badly as it does a string.

      Each database handle the results of a number / null differently. Some allow you to predefine the variable and the math will return a zero and some will return a null.

      Null division is annoying but 0 division is sometimes catastrophic.

      Wolj

      --
      Wolja Future Tombstone: Shit happened then I died
    8. Re:Nulls are annoying by Anonymous Coward · · Score: 0

      Fully normalized databases are in general a mythical beast best avoided.

      E.g. observe the fact that the letter "a" is used in many places. Should we not replace all occurences of the letter "a" with references to a table somewhere?

      A truly, fully normalized database is like a Turing machine. A useful concept, but you can't make one, and you probably wouldn't use one if you could.

    9. Re:Nulls are annoying by dcam · · Score: 1

      I take it we are talking 3NF here? To suggest that a fully normalised table contains just a key-value a pair is nuts. What you are saying is that only one column can ever depend on a key. ?Que?

      Simple example. Storing information about people.

      PersonID [PK]
      FName
      LName

      Oh dear. We've hit two rows already. It would also be perfectly valid to store a NULL in either FName or LName, as that would mean that you knew only this person's first name or their last name.

      3rd normal form in summary says:
      1. Atomicity, ie only 1 value in a column
      2. Requires 1NF. All columns must be functionally dependant on the whole primary key rather than just a part of the key.
      3. Requires 2NF. All columns should be dependant on the primary key.

      --
      meh
    10. Re:Nulls are annoying by MattRog · · Score: 1

      3NF is certainly not fully normalized.

      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).

      --

      Thanks,
      --
      Matt
  26. Good jumping off point... by djrisk · · Score: 3, Insightful
    I think that this book sounds like a good jumping-off and/or refresher product. Like any language, it's always good to have a couple of good references (both printed and on-line) available to you.

    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.

  27. What does SQL stand for then? by AmbushBug · · Score: 1

    If SQL doesn't stand for structured query language, what does it stand for? Or is this guy just full of sh*t? This also is mentioned in "The Free On-line Dictionary of Computing (09 FEB 02)" and is attributed to Allen G. Taylor. Can anyone clear this up?

  28. SQL In A Nutshell by rakanishu · · Score: 2, Informative

    O'reilly's SQL In A Nutshell is pretty good. It covers standard SQL and the differences between each database(Oracle, MySQL, Postgre SQL, MS SQL).

  29. Chris Fehily by Kai_MH · · Score: 1

    I find Fehily's approach to teaching different languages very unaffective and unorganized. I own his Python book, and have sampled many of his other works.

  30. Correction! by quasi_steller · · Score: 1

    Hate to reply to my own comment, but I said that wrong. A binary search is O(lgn) not O(nlgn).

    --
    ...interesting if true.
  31. your sig is spelled wrong by Anonymous Coward · · Score: 0

    HERD, not heard

    1. Re:your sig is spelled wrong by AKAImBatman · · Score: 1

      Whoops. Muscle memory there. Thanks for the pointer. :-)

    2. Re:your sig is spelled wrong by Anonymous Coward · · Score: 0
      That's "band of gorillas", not herd.

      (Still a better choice in context than a "crash of Rhinoceroses" or a "bloat of Hippopotamuses"!)

    3. Re:your sig is spelled wrong by AKAImBatman · · Score: 1

      > That's "band of gorillas", not herd.

      Don't be rediculous. It's *supposed* to be nonsensical and silly.

  32. Huh? by BoomerSooner · · Score: 1

    TransactSQL is the Sybase/MS implementation of SQL
    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 ;)

    1. Re:Huh? by AKAImBatman · · Score: 1

      TransactSQL is the Sybase/MS implementation of SQL
      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 after a trigger inserts into a secondary table. @@IDENTITY will be set to the secondary table id and _not the one you inserted into_! Stupid, isn't it?

    2. Re:Huh? by smittyoneeach · · Score: 1

      Uhhh, I'd call PL/SQL the Procedural Language extensions for SQL, which implies quite a bit more than implementation, or perhaps I'm having a pedantic moment.
      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 you might as well write in C to begin with. ;)

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    3. Re:Huh? by oZZoZZ · · Score: 1

      umm... they look nothing like C... when I first started with pl/sql (and plpgsql for that matter), my first thought was "wow, pascal"... after a bit of reading, I found out that both languages came from ADA... not C. ez.

    4. Re:Huh? by mal3 · · Score: 1

      SCOPE_IDENTITY() gets you the right identity every time. It's only in SQL Server 2000 though.

      Mal

      --
      Non gratis rodentus anus
    5. Re:Huh? by smittyoneeach · · Score: 1

      I wasn't clear. Yes, PL/SQL draws heavily from ADA.
      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.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    6. Re:Huh? by BoomerSooner · · Score: 1

      The primary reason I chose oracle over mysql/postgres/sql server is because their jdbc drivers are world class. Plus I love pl/sql. If only one of my companies would hurry up and make me a multimillionaire I could just play all day instead of having to worry about cash flow, profit, receivables, etc...

      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 be expected).

  33. One thing I've become enamored of by smittyoneeach · · Score: 1

    Is doing queries like:

    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 "that's too advanced for the FNG coders we prefer to hire to maintain"?

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    1. Re:One thing I've become enamored of by Anonymous Coward · · Score: 0

      Nice!

    2. Re:One thing I've become enamored of by Anonymous Coward · · Score: 1, Interesting

      Yes--there is a huge problem with using this as a generic solution. It doubles the time needed to get an answer back. For a query that is rarely run and is fast, this probably isn't a problem. For a query that is either frequently run or takes a long time to return (or worst, both), you have just doubled the impact of an already expensive statement. Impact not just equaling time, of course, but also CPU usage and lengthening the duration of sort-space usage (for queries whose plans require sorts/hash joins).

      So--in a _limited_ number of cases the above might be OK, but I would shy away from suggesting that as a "generally good thing to do".

    3. Re:One thing I've become enamored of by MattRog · · Score: 1

      What is the benefit to this? I don't get it. Well, I do, but I don't see how it is that entirely too useful.

      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 not true if the count is using an index. Index scans are usually very fast.

      --

      Thanks,
      --
      Matt
    4. Re:One thing I've become enamored of by smittyoneeach · · Score: 1

      Good points.
      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.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  34. Re:Wait a minute... by Anonymous Coward · · Score: 0

    Well, they do find "Kids In The Hall" funny. Bryant Gumbel must be hilarious to them.

  35. DBAs? by MemeRot · · Score: 3, Insightful

    Uh.... where did you get your DBAs? Do they understand that stored procedures offer performance benefits by reusing a stored execution plan? That stored procedures encourage code reuse just like function libraries in the procedural language of your choice? That by isolating a block of code away from being embedded in code it's much easier to put in the finnicky lock control statements that you generally don't want mucked about with by junior programmers? That by moving back to embedded SQL you are probably giving up control of locking mechanisms whatsoever? That you are quite likely moving sorting/selecting logic out to your embedding code, and away from the database engine that is much more optimized for these operations, offering advanced tools like cursors and temp tables?

    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.

    1. Re:DBAs? by AKAImBatman · · Score: 1

      Stored Procedures are overrated. They do offer some benefits in performance, but people have a nasty way of using them for anything and everything, thus making a general mess out of the database. Not to mention that embedded SQL is far easier to make dynamic than Procs. Remember, Web Apps are the name of the game these days. Most of them hardly require the level sophistication you're referring to. :-)

      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 have the same problem with procedures. Change your table structures and you have to go back through all the procs and change them. I've always architected my systems so that DB Access code is a separate segment anyway, wrapped in a nice coding API. That way there's one location, but you get the benefits of have SQL be dynamic. And if anything *needs* a proc, you can still create it and call that instead.

    2. Re:DBAs? by crazyphilman · · Score: 1

      I know what you're saying... Most of us programmers said the same things. Ah, well, what can you do? Go along to get along, etc.

      --
      Farewell! It's been a fine buncha years!
    3. Re:DBAs? by mal3 · · Score: 1

      No offence but that's heresy where I come from. Everything must be an SP here. Would you want to recompile every line of app code before you execute it(java devs don't answer that). It's the same way with stored procedures.

      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.

      --
      Non gratis rodentus anus
    4. Re:DBAs? by AKAImBatman · · Score: 3, Informative

      No offence but that's heresy where I come from.

      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.)

    5. Re:DBAs? by mal3 · · Score: 1

      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".

      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 compile. On the other hand those other 90% of calls you make I still belive need to be stored procs. The difference may not be much but what you save in network bandwidth, and optimizer time adds up. Besides it's not like it's hard to write a simple stored proc in *any* SQL language. It's only the complex ones, which you said need to be in sp's anyhow, that are difficult.

      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.

      That sounds contradictory to me. At one point you're complaining about about DBA's insisting that things be done for performance reasons, at another you want it to just get done, and another you want it done right. These aren't things you can have all at the time, sometimes you can when I'm your DBA ;). Much of the time the 'get it in production now' attitude is what leads to performance problems 2 years down the road when the new DBA (re: Me) takes over to fix the deadlocks, timeouts, and poor usage of DB resources.

      --
      Non gratis rodentus anus
    6. Re:DBAs? by Anonymous Coward · · Score: 0

      Uh.... where did you get your DBAs? Do they understand that stored procedures offer performance benefits by reusing a stored execution plan?

      Most DBAs understand your points. However, stored procs often implement business rules and business logic and if you're a DBA responsible for keeping 25 servers and 100 databases happy and well maintained and recoveable you probably don't have time to be intimately familiar with the details of those rules and logic wrapped inside of stored procs.

    7. Re:DBAs? by AKAImBatman · · Score: 2, Interesting

      The difference may not be much but what you save in network bandwidth, and optimizer time adds up. Besides it's not like it's hard to write a simple stored proc in *any* SQL language.

      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 when it comes to SQL statements and optimizer time is negligable for most simple select, insert, and update queries. Most databases expect the little cases. It's the rare, big ones that test its metal.

      These aren't things you can have all at the time, sometimes you can when I'm your DBA ;). Much of the time the 'get it in production now' attitude is what leads to performance problems 2 years down the road when the new DBA (re: Me) takes over to fix the deadlocks, timeouts, and poor usage of DB resources.

      I'm probably didn't come across as clear as I'd like. There are well know, well understood patterns for developing databases. The two most common and easiest to apply are applying the rules of normalization, and object/relational design.

      The rules of normalization tell you how to build the database so that everything functions well in a relational world. Too many "database brains" ignore these to try "fun" concepts like a "winding heirarchical" structure. It's supposedly faster than a simple parent key design, but you have to be a friggin' PhD to follow the blasted thing.

      Object relational is a good design principle that trips up many DBAs. Often, a DBA will take the attitude that as long as the data is _somewhere_ and it follows the relational rules, it's okay, right? Wrong. Every table/view should follow a well defined concept. For example, you should have a table for a Product, not a table of ids over here and details over there, and other weird ass ideas. This sort of structure also encourages object type heirarchies. (i.e. The "Product_Color" table gives potential options for the color field of a product).

      Follow these simple design concepts and your database will come out right the first time and will be quite simple to build. Plus it leaves plenty of open breathing room to do optimizations and additions to the database later on.

    8. Re:DBAs? by afidel · · Score: 1

      Stored procedures break the three layer approach that many people is the most mature way to do application development. You have the presentation layer (the client facing app or web servers), the logic layer (middleware servers with the business logic), and the data layer (the SQL servers). This layout makes things easier to maintain and more independant. They may not perform optimally but they scale like nobodies business and given decent developers will perform pretty close to the optimized case.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    9. Re:DBAs? by MattRog · · Score: 1

      But the 'business logic' (depends on your definition of business logic, really) is intrinsically tied to the data. Without it, your data is meaningless.

      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 rules engines' are declarative and not procedural, but it still needs to be under control of the RDBMS.

      --

      Thanks,
      --
      Matt
    10. Re:DBAs? by mal3 · · Score: 1

      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.

      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 able to find anything in there either. I think it's easier to have *all* the stored procs in one place organized well rather than two places organized well. On a side note I think Oracle does allow you to group stored procs into packages.

      I'm really having a hard time figuring out what you find is so difficult about managing stored procs in databases. Maybe you can tell me the difficulties you have and I can understand better.

      Bandwidth internal to a network is nothing when it comes to SQL statements and optimizer time is negligable for most simple select, insert, and update queries. Most databases expect the little cases. It's the rare, big ones that test its metal.

      I agree the difference is minimal. But when you're trying to run 2000 transactions per second through a database a small lag makes a big difference. Maybe not in most cases but definitely some. We have a database here that processes 500000 of our work units an hour. Add a few milliseconds to each of those querys and it drops signifigantly.

      --
      Non gratis rodentus anus
    11. Re:DBAs? by jfx32 · · Score: 1

      Performance isn't the only reason to use stored procedures. Dynamic SQL in a Web Application is vulnerable to SQL Injection flaws, this isn't true of stored procedures. Also you can do dynamic SQL in PL/SQL if you really need to, by evaluating a string as a SQL statement. This requires some validation of input (which should always be done :) so you don't open yourself back up to code injection flaws.

    12. Re:DBAs? by MemeRot · · Score: 1

      I find 'middle layer' getting very small in my apps now. The point of the middle layer is to allow for easy business rule changes but... I didn't want to hardcode in tax rates, so I move them to the database. I didn't want to hardcode in discount rates, coupons, promotion codes, etc. so I move all that to the database. Pretty soon my middle layer looks pretty skinny.

  36. We're not all as clever as you by Anonymous Coward · · Score: 0

    So YOU! don't find this sort of book useful and YOU! won't need to buy it. That's great. Thanks for sharing that with us. Really.

  37. i don't think so... by MemeRot · · Score: 1

    How is the result of this
    "SELECT DISTINCT tblCalender.CalenderID AS ID, tblActivity.Activity AS
    ActivityType, tblCalender.ActivityDesc, tblProductFamily.ProductFamily,
    tblProductCategor y.ProductCategory, tblStage.Stage, tblStatus.Status"
    possibly going to be 3? 7 fields and 7 values unless i'm crazy.

    1. Re:i don't think so... by jpkunst · · Score: 1
      How is the result of this [...] possibly going to be 3? 7 fields and 7 values unless i'm crazy.

      Three rows?

      JP

  38. why would i use isnull? by MemeRot · · Score: 1

    Because it's clear what isnull does just from looking at it. Coalesce isn't. I've never ported systems from one database engine to another, only to other versions (not counting upsizing access). So I don't see how portable could actually offers a benefit for databases. People are too damned scared to move them even when they should.

  39. I know :) Or Select INTO by MemeRot · · Score: 1

    Select certainly can insert data

  40. The problem with Peachpit Press books by pongo000 · · Score: 1, Informative

    I've had the (mis)fortune of having to teach courses in Unix using the Visual Quickstart Guides. (I've also checked out several of the other books in the series.) The problem with these books is that they teach by example with very little theoretical background. There's nothing wrong with teaching by example, but if it isn't set in a strong foundation, you end up with students that might have breadth of understanding, but no depth. The books themselves become useless at this point, as the examples are often so narrowly contrived that it's difficult to extrapolate them into more generic scenarios.

    There's nothing worse than to see students pay good money for books that will be obsolete or of little use as soon as they finish a class. God knows I bought enough of them when I was in school. For this reason, I avoid the Visual Quickstart Guides and opt for textbooks with more depth of coverage.

    1. Re:The problem with Peachpit Press books by yoriknme · · Score: 1

      Yes, great depth is appropriate for a class. The Quick start guides are only for those who need, well, a start outside a guided environment. Ive used them to review or learn something in a few hours.

    2. Re:The problem with Peachpit Press books by gh · · Score: 3, Insightful

      You, as the instructor, could have filled in those gaps. It would be better if you didn't depend solely on the Visual Quickstart Guides. If that's all you had to work with in the course, you could have fleshed out the course more with your own instructional material and knowledge.

      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, hand-outs, and other resources.

      The most important resource that's available to students should be our own knowledge developed over the years. It should not be coming strictly from a book.

    3. Re:The problem with Peachpit Press books by afidel · · Score: 2, Informative

      Who cares, this isn't a $200 Calc text, it's ~$15 at most of the major online retailers. It's kind of like cliff's notes or dummies books, enough to get you started but not something you learn everything you need from.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
  41. It's not clear by metamatic · · Score: 1

    The Ingres project used a database query language called QUEL, short for QUEry Language.

    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 QUEL. The S, Q and L did originally stand for "Structured", "Query" and "Language", but at different times during the evolution of the final terminology...

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    1. Re:It's not clear by Anonymous Coward · · Score: 0
      Your history is wrong. QUEL and SEQUEL were developed in parallel, inependent of each other.

      Both of them were inspired by Codd's 1970 CACM paper.

    2. Re:It's not clear by Anonymous Coward · · Score: 0

      I beleive your history is wrong. iirc sequel was created as a follow up to quel, but the folks who made it got sued by the folks who made quel and so had to change the name. they changed it to sql since that looks like it could be pronounced "sequel". it never stood for anything until someone thought it should and started making up definitions.

      (btw - wheres pascal or date when you want a history lesson eh?)

  42. Re:Why not to use the vendor-specific documentatio by Anonymous Coward · · Score: 0

    And they fold case on identifiers to lower instead of upper. Makes it more readable, but some tools don't handle having identifiers fold to lower case well.

  43. I've got a funny geek joke you'll enjoy! by Anonymous Coward · · Score: 0
    Q: Why do programmers confuse Columbus day and Armistice day?

    A: Because you're an overly-literal anal retentive nerd!

  44. Sell 'em [Re:Yet another programmer's reference] by irontiki · · Score: 1

    I already have 5 or so $50 books that are currently serving as expensive doorstops.

    Do what I'm doing and unload the books that you can spare on Amazon or Ebay. Ten bucks in my pocket beats the ten useless kilos on my shelf.

  45. I got this book a couple of weeks ago. by Frank+Grimes · · Score: 1
    It was cheaper than the cheapest O'Reilly book on the subject, and it had just enough information about SQL to get me started (I had never used SQL before, even tough I used to program for an older database system.)

    To suppliment the book, I have these two pages bookmarked: http://www.perldoc.com/perl5.6.1/lib/DBI.html and http://www.mysql.com/documentation/mysql/bychapter /

    I still want to read Programming the Perl DBI as well, which looks like a useful book for what I want to do.

    --
    CfkRAp1041vYQVbFY1aIwA== RV/hBCLKKcSTP5UFK3kqsg==
  46. Say what? by Anonymous Coward · · Score: 0

    six separate DBMSes: Microsoft Access 2002,

    Somebody who starts a list of databases with Microsoft Access doesn't understand what a database is. Hint: Access is not a database, it's a program for maintaining and manipulating tables and generating reports from the data in them.

    1. Re:Say what? by REBloomfield · · Score: 1

      erm... what's the JET Engine that sits behind it then? toilet paper?

  47. SQL:1999 by tarvin · · 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 SQL" nowadays (or ISO/IEC SQL), not "ANSI SQL".

    Apart from that, I've put the book on my Safari bookshelf and look forward to reading (at least parts of) it. Unfortunately, it seems that Safari's index of the book is currently lost.

    I like the approach where you start by thinking about the standard way to do it, and then try to squeeze your design into a real-World product. It's too bad that the official standard isn't online; fortunately, it's possible to get something close to being official. When trying to set up an initial, standards compliant schema, it's nice to have an evaluation-installation of Mimer SQL to play with. I wish it were open source or at least had an official price tag.

    I expect that the book could be relevant in connection with a page about SQL differences that I've started writing, after having had to port some SQL from PostgreSQL to MSSQL.

  48. coalesce by brlewis · · Score: 1

    The other nice thing about coalesce() is that it takes an arbitrary number of arguments, and returns the first non-null, so you can do coalesce(a, b, c, d) rather than isnull(a, isnull(b, isnull(c, d))).

  49. Woop:For those of you who use Linux or Mac OS X... by mal3 · · Score: 1

    Vaguely related to the product, is what I meant to say up there.

    --
    Non gratis rodentus anus
  50. Visual Quick Start == good by Bob+The+Lizard · · Score: 1

    I used a couple of the Visual Quick Start books as references several years ago. If they have kept up the quality, then they should be considered, by anyone after tech references.

    Still how does anyone find enough info to fill a book on SQL?.

  51. If you're teaching Unix...[OT] by Big+Sean+O · · Score: 1

    If you're teaching Unix to a group of computer users, you might want to check out Think Unix by Jon Lasser.

    I bought it shortly after I first installed Linux.
    The book starts out on how to use man pages (and other forms of sparse documentation) to learn new commands. From there it teaches how to make aliases, use pipes, and redirect output. It eventually tackles vi, shell programming, changing your environment, and the X-Windows system.

    It's a pretty good book which treats you like you know your way around a comuputer, but are new to *nices.

    --
    My father is a blogger.
  52. Oh my god... The ignorance... blinds... me by 3770 · · Score: 1

    Where I come from, 0 is also a number that is used, for instance, when you count your apples and you have no apples. Wait, you say, then use -1, well, that is what we use when we owe someone an apple. Whatever number you come up with, that is conceivably how many apples someone has or owes to someone else.

    NULL is used to denote that the value is undefined. It is consistent for all data types.

    In reply to the parent post (by MattRog) of your post, how on earth can a fully normalized database save you from not having to use NULLs? I'm sorry, I just can't follow your point.

    I'd like to suggest that you follow the advice of at_kernel_99. If you don't want a value to be NULL, declare the column as not null. Problem solved.

    Finally, to the parent post of at_kernel_99, if a NULL value can ruin a string, and you can't solve it by using at_kernel_99's excellent advice of declaring your string columns not null, why don't you use the SQL standard function called coalesce.

    Instead of writing str1 + str2 and watch it be destroyed because one of them is null, write this

    coalesce(str1, '') + coalesce(str2, '') --'' <-- this is actully two single quotes

    Coalesce replaces the first argument with the second argument if it is null. In fact, you can give it any number of arguments and it will walk forward in the argument list until it finds a non null value.

    coalesce(mayBeNull1, mayBeNull2, mayBeNull3, ' IGiveUp')

    I apologize in advance for stepping on your toes. I had a bad day at work (where I program in SQL, among other things, for a living).

    --
    The Internet is full. Go Away!!!
    1. Re:Oh my god... The ignorance... blinds... me by Tablizer · · Score: 1

      Whatever number you come up with, that is conceivably how many apples someone has or owes to someone else.

      Generally, auto-generated ID's are not zero or -1.

      If all else fails, then use another Boolean field to indicate if something is missing.

      I'd like to suggest that you follow the advice of at_kernel_99. If you don't want a value to be NULL, declare the column as not null. Problem solved.

      Yes, but sometimes the DBA or you forget that rule, and Nulls sneak in. Note that you also have to remember to add a default value, or else you need to include something for each slot on INSERT.

      why don't you use the SQL standard function called coalesce.

      I am not sure it is standard/common. Each dialect seems to have a different de-nulling function. Plus, it bloats up the SQL code.

    2. Re:Oh my god... The ignorance... blinds... me by 3770 · · Score: 1

      Generally, auto-generated ID's are not zero or -1

      This is true, but generally, most fields aren't auto-generated ID's. And auto generated ID's are most definitely not NULL.

      If all else fails, then use another Boolean field to indicate if something is missing.

      Below you say that using coalesce would bloat the code, yet you suggest that a second column should be used and handled separately in your code?

      Yes, but sometimes the DBA or you forget that rule, and Nulls sneak in. Note that you also have to remember to add a default value, or else you need to include something for each slot on INSERT.

      This is true, but for most cases the best way to solve that is to make that column not nullable in retrospect. If there already are null values there and you wan't them to be the empty string, or something else, then that can be fixed with a simple update statement.

      I am not sure it is standard/common. Each dialect seems to have a different de-nulling function. Plus, it bloats up the SQL code.

      coalesce is standard and is supported by at least DB2, Oracle, Mimer SQL Engine and MS SQL Server.

      --
      The Internet is full. Go Away!!!
    3. Re:Oh my god... The ignorance... blinds... me by Tablizer · · Score: 1

      This is true, but generally, most fields aren't auto-generated ID's.

      Most *keys* ARE generated ID's in my experience. If they are external keys, then often it is best to make them string instead of numeric in case they change type in the future. In that case, just use a blank to represent a missing key. I used to use pre-SQL DB tools that had no Nulls, and I did not miss them. Even if you are stuck with numerics set by someone else, I have never seen a legit *negative* key. Thus, I won't lose sleep over the one-in-a-billion chance that it might occure.

      And auto generated ID's are most definitely not NULL.

      I don't see how this relates to the discussion.

      Below you say that using coalesce would bloat the code, yet you suggest that a second column should be used and handled separately in your code?

      I said as a last resort. It would not happen often. I try to focus on simplifying the common stuff first, and appending strings is common.

      This is true, but for most cases the best way to solve that is to make that column not nullable in retrospect.

      This depends on how much control one has over the schema.

      coalesce is standard and is supported by at least DB2, Oracle, Mimer SQL Engine and MS SQL Server.

      You are right. I will give you that one. (It is such an oddly-named operation.)

    4. Re:Oh my god... The ignorance... blinds... me by 3770 · · Score: 1

      I don't see how this relates to the discussion.

      And that was actually the point I was trying to make. What does auto generated keys have to do with our discussion about whether NULLs are a poison pill or not?

      --
      The Internet is full. Go Away!!!
    5. Re:Oh my god... The ignorance... blinds... me by Tablizer · · Score: 1

      And that was actually the point I was trying to make. What does auto generated keys have to do with our discussion about whether NULLs are a poison pill or not?

      The link between keys/ID's and null need was *not* mine. I never linked nor meant to link key/ID's and "poison pills". I already described how I handle missing keys/ID's WITHOUT nulls, and not using Nulls for them has never been a problem for me. If anybody has a problem with such, I would like to hear specifics.

      Just get rid of nulls in strings and I will be happy. Strings don't need nulls of any kind. I have never seen a good justification of nulls with strings. Math, maybe. Strings, no.

    6. Re:Oh my god... The ignorance... blinds... me by MattRog · · Score: 1
      In reply to the parent post (by MattRog) of your post, how on earth can a fully normalized database save you from not having to use NULLs? I'm sorry, I just can't follow your point.


      Because 'nulls' (or so-called three value logic) have no place in the relational model. Either you have a value or you don't.
      --

      Thanks,
      --
      Matt
  53. I believe in separation of layers by MemeRot · · Score: 1

    And firmly believe the data layer needs to be at least two separate layers itself.

    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 specified by the DBAs. There is often some overhead with connecting to the database too - if not for an actual connection then in instantiating variables to hold the results. If you need to query three separate times to get what you're lookign for, most web developers write three separate queries - its very rare to see embedded SQL that makes use of database variables as opposed to programming variables. So that helps too.

    Stored procedures should be written to be atomic in nature, skipping the CRUD procs is what results in your 'you have to rewrite all the procs'. You need a group of low level procs that do insert, delete, etc that should be called by higher level scripting like procs. Then you just modify the lower level procs and the higher level ones are fine.

  54. you can do it with tsql too by MemeRot · · Score: 1

    by using the system stored proc sp_executesql

  55. It's NOT 3-tier, its N-tier by MemeRot · · Score: 1

    Each layer can be subdivided. I divide the database layer into 3 layers itself: tables, CRUD, complicated procs. It's all about code re-use and maintenance. You write the dumb CRUD procs to handle your basic inserts, updates, etc. You call them from the more complicated procs. The role of the complicated procs is to accept a big chunk of data and format it for the tables. Lets say your middle tier has a nice xml document representing the contents of a shopping cart. Fine, the business logic is done. It passes that to a stored proc. The proc takes care of putting the pieces where they belong. This way the middle tier com object doesn't need to be recompiled (and the web server stopped for re-registration) when a data field changes length. Now that stopping/stopping the site thing doesn't apply to .Net, but we're not on .Net.

    I divide the front end code into three layers too. The topmost layer being DHTML and client side script (what do you see in your screen), next HTML (what is sent to the browser), next ASP or your other server-side scripting language (what generates the other two and interacts with the middle tier).

    MS doesn't go far enough because they're lazy. The front end shouldn't know anything about the database, definitely. The middle tier shouldn't know anything about the database except for calling stored procs. That lets you completely divorce the best way to handle the data from the best way to handle middle tier logic - your data structure should be driven by normalization and performance of the data, not by modeling what the middle tier does since that leads to poor database structure. Also by allowing 1 call to the database from the middle tier to generate an arbitrary amount of SQL processing, you cut down on unneccesary traffic. Now, you CAN write out the text of a stored proc as one big string and execute it from the middle tier - but it won't stay like that because programmers will tend to move things to programming language processing and away from database variables and cursors just as a rule of thumb.