Home > Store

Practical SQL Handbook, The: Using SQL Variants, 4th Edition

Register your product to gain access to bonus material or receive a coupon.

Practical SQL Handbook, The: Using SQL Variants, 4th Edition


  • Your Price: $55.99
  • List Price: $69.99
  • We're temporarily out of stock, but order now and we'll send it to you later.



Judith S. Bowman has been a database professional since the early 1980s. She is currently an independent consultant specializing in SQL and relational database issues and is the author of Practical SQL: The Sequel (Addison-Wesley, 2001). Sandra L. Emerson is an independent consultant and former Vice President of Publishing Programs for Sybase. Marcy Darnovsky, teaches at colleges throughout the San Francisco Bay area. She was formerly at Sybase.



  • Copyright 2001
  • Dimensions: 7-3/8" x 9-1/4"
  • Pages: 512
  • Edition: 4th
  • Book
  • ISBN-10: 0-201-70309-2
  • ISBN-13: 978-0-201-70309-2

This latest edition of the best-selling implementation guide to the Structured Query Language teaches SQL fundamentals while providing practical solutions for critical business applications. The Practical SQL Handbook, Fourth Edition now includes expanded platform SQL coverage and extensive real-world examples based on feedback from actual SQL users.

The Practical SQL Handbook begins with a step-by-step introduction to SQL basics and examines the issues involved in designing SQL-based database applications. It fully explores SQL’s most popular implementations from industry leaders, Oracle, Microsoft, Sybase, and Informix.

Highlights include:

  • Detailed coverage of SQL commands for creating databases, tables, and indexes, and for
  • adding, changing, and deleting data
  • Using the SELECT command to retrieve specific data
  • Handling NULL values (missing information) in a relational database
  • Joining tables, including self joins and outer joins (ANSI and WHERE-clause syntax)
  • Working with nested queries (subqueries) to get data from multiple tables
  • Creating views (virtual tables) to provide customized access to data
  • Using SQL functions

A bonus CD-ROM contains a time-limited, full-feature version of the Sybase® Adaptive Server Anywhere™ software as well as the sample database, scripts, and examples included in the book.

The Practical SQL Handbook is the most complete reference available for day-to-day SQL implementations.



Source Code

Click below for Source Code related to this title:




Sample Content

Online Sample Chapter

Practical SQL: Creating and Using Views

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:

Table of Contents



 1.SQL and Relational Database Management.

 2. Designing Datases.

 3. Creating and Filling a Database.

 4. Selecting Data from the Database.

 5. Sorting Data and Other Selection Techniques.

 6. Grouping Data and Reporting from it.

 7. Joining Tables for Comprehensive Data Analysis.

 8. Structuring Queries with Subqueries.

 9. Creating and Using Views.

10. Security, Transactions, Performance, and Integrity.

11. Solving Business Problems.

Appendix A: Syntax Summary for the SQL Used in This Book.

Appendix B: Industry SQL Equivalents.

Appendix C: Glossary.

Appendix D: The 'bookbiz' Sample Database.


Why New Editions?

Many things have changed since this book was first published in 1989, and SQL is no exception. The SQL language has expanded tremendously, both in numbers of users and in numbers of commands. Sales of relational databases continue to rise at a strong and steady rate.
      When we wrote the first edition of The Practical SQL Handbook, the American National Standards Institute (ANSI) had already approved the 1986 SQL standard. The International Standards Organization (ISO) adopted it in 1987. Both ANSI and ISO helped create the 1989 version. The 1986 standards were skimpy, lacking features that most commercial vendors offered. The 1989 standards were more complete but still left many important elements undefined.
      For the first edition, we felt we should focus on industry practice: As always, each vendor was keeping a wary eye on what the others were doing and making core offerings similar enough to attract both customers migrating from competitors, as well as new users looking for database systems they could build on. Because of this, we left both the not-quite-jelled ANSI standards and particular vendor implementations to the experts in those fields and concentrated on the common ground: generic or "industry-practice" SQL. Our goal was to offer the intelligent amateur practical information on how to use the actually available SQL of that time.
      The 1992 ANSI standard (often called SQL-2 or SQL-92) represented a new stage in SQL development. This standard was more comprehensive than the 1989 standard: In written form it contained more than four times as many pages as the earlier version. Database vendors have adopted large parts of the 1992 standard. With the widespread adoption of the SQL-92 standard, the industry practice and the ANSI/ISO standards began to converge.
      Despite vendor-specific differences, there is a general, industrywide core of SQL commands that all users need to understand. Adopting standards doesn’t happen overnight; it is a long process. At any point, vendors will have varying levels of conformance and will continue to produce vendor-specific variations. This book aims to give SQL users a mastery of the fundamentals of the language, with a side glance at the specifics of particular implementations.

Changes for Recent Editions

The changes for recent editions have been threefold:
  • To include more real-world examples
  • To emphasize the SQL-92 features that most vendors have imple-mented
  • To provide software for hands-on practice
  • Include More Real-World Examples

    In talking to new and developing SQL users, we heard over and over of their need for more examples to follow, change, narrow, and broaden. Accordingly, the bulk of the added material in the second edition consisted of code "recipes." Chapter 11, Solving Business Problems, is a selection of code samples based on questions and answers that came over computer newsgroups. We reproduce interesting problems and solutions in terms of the sample bookbiz database used throughout the book. The chapter includes examples of using the CASE function for conditional logic, formatting results, and finding date data. A few samples fall into a different category. They aren’t so much solutions to problems as indications of common errors. They include issues with DISTINCT and misunderstandings of what SQL can do.

    Emphasize SQL-92

    With the third edition, we revised the book to incorporate the SQL-92 features that most vendors had adopted. These include new datatypes, additions to the CREATE TABLE statement that allow built-in integrity constraints, modifications to the ORDER BY and GROUP BY clauses, the new escape character for the LIKE keyword, and changes to GRANT and REVOKE, among others.

    Provide Software for Hands-On Practice

    With the fully usable trial version of Sybase’s Adaptive Server Anywhere (ASA) on the CD that accompanies this book, you can run the examples (and your variants) on a PC. We’ve always felt that the secret to learning SQL is practice. Now you can experiment to your heart’s content, trying out code samples with data you know and checking the results to see if they are what you expect. When you’re stumped by complicated code, break it into small, meaningful pieces and run the pieces separately to make sure you understand what each segment does. Then put them together in increasingly complex combinations–and have fun!
          The Sybase Adaptive Server Anywhere software on the CD is a 60-day full-feature version that allows you to create objects as well as to query existing objects. ASA is built with an updated version of the bookbiz database: For the fourth edition, we increased book prices and made dates more recent. Also included on the CD are scripts to create the database on ASA (in case you damage the original) and on the other systems discussed in the book.

    The Fourth Edition

    The Practical SQL Handbook, Fourth Edition, continues to focus on industry-practice SQL, but the information included is at once more general and more specific than earlier editions. For the fourth edition, we had two objectives:
  • To expand our test base, running the examples on five different database systems
  • To show vendor-specific differences among systems
  • Test on More Systems

    For the fourth edition, all examples were run on five systems (Sybase Adaptive Server Anywhere, Adaptive Server Enterprise, Microsoft SQL Server, Oracle, Informix), rather than on Sybase systems only, as in the third edition. This expanded test base makes the information more universal. We are no longer limited to what we can explore or verify on a particular system. If an important feature doesn’t exist on Adaptive Server Anywhere (ASA, the RDBMS included on the CD), we can show code and results from Oracle or SQL Server.

    Show Examples of Vendor-Specific Differences

    On the other hand, this edition is more specific. It includes information on specific idiosyncrasies of the five SQL dialects, warning readers where to look for differences. In this, it reflects the real world–lots of database users are working with multiple systems, either sequentially or simultaneously. Interesting SQL differences are flagged as SQL Variants, in-text sections that show details of differences in SQL use by different vendors. For example, how single and double quotes are used, or database users added, or outer joins specified. You won’t see code for every one of the five systems every time, but you’ll get an introduction to the kind of differences that are likely in a particular area.


    We would like to thank the following people for their contributions to this book: Donna Jeker and Stu Schuster for supplying timely support and encouragement; Jeff Lichtman and Howard Torf for offering advice, examples, anecdotes, and reality checks; Tom Bondur, Susie Bowman, John Cooper, and Wayne Duquesne for providing resource materials and other information; Paul Winsberg for reviewing the database design chapter in the first edition; Robert Garvey for technical review of the second edition; Karen Ali for facilitating the third edition’s SQL Anywhere CD; and Theo Posselt for technical review of the third edition.
          For the fourth edition, we would like to acknowledge Mike Radencich of iAnywhere Solutions (a Sybase Company), for providing the software and permissions for the Adaptive Server Anywhere CD; Lance Batten of Tilden Park Software and Sanford Jacobs of Paragon Software for comments and corrections; our reviewers, on whom we rely for timely and detailed feedback: Vijayanandan Venkatachalam, curriculum director of Oracle Corporation; David McGoveran of Alternative Technologies; Roger Snowden; Amy Sticksel of Sticksel Data Systems; Paul Irvine of Emerald Solutions; and Karl Batten-Bowman.



    *, See asterisk

    %, See wildcards

    _, See wildcards

    --, See comment marks

    /*, See comment marks

    */, See comment marks

    ||, See concatenation

    +, See concatenation

    *=, See outer joins

    =*, See outer joins

    (+), See outer joins

    . . ., See ellipses

    — A —


    in views, 325

    permissions in, 15, 315

    strategies in, 5, 387

    Adaptive Server Enterprise, 178–179


    columns, 300–301

    rows, 83–93

    aggregate functions, 143, 162–172, 192, 387

    AVG, 164, 165, 166

    COUNT, 164, 165, 166

    COUNT (*), 164, 165

    datatypes and, 165–166

    DISTINCT with, 166, 371, 373–375

    GROUP BY clause, 175–192

    with, 187–188

    without, 186–187

    grouping and, 175

    in guaranteeing single value, 267–268

    MAX, 164, 165, 166

    MIN, 164, 165, 166

    NULL values and, 170–171

    scalar, 175–176

    SUM, 164, 165, 166

    syntax of, 164

    vector, 175

    views and, 308–309

    WHERE clause and, 169–170

    aliases, 150, 259, 387

    in FROM clause table/view list, 216–217

    in SELECT clause, 103

    ALL, 100, 155–162, 253

    comparing with IN and ANY, 263

    subqueries with, 259–266

    ALTER COLUMN, 80–81

    ALTER commands, 79


    ALTER TABLE command, 80–81

    ALTER clause in, 80

    DELETE (DROP) clause in, 80

    joins and, 208

    MODIFY clause in, 80, 81

    ANALYZE, 334

    AND, 121, 221

    semantic issues with, 122–123

    ANSI standard, 16, 32–33, 353

    on views, 306–310

    anti-join, 256, 387

    ANY, 253, 259–266

    comparing with IN and ALL, 263

    subqueries with, 259–266

    apostrophes, embedded, 106–107

    argument, 388

    arithmetic operators, 61, 100, 107–109, 388

    precedence in, 111–114

    AS, 284–285

    in CREATE VIEW, 284

    in display label, 103–104

    ASC, 149

    association, 36, 388

    asterisk (*)

    in asking for columns, 6

    in comments, 225

    with COUNT, 165

    indiscriminate use of queries, 215

    in outer joins, 226-227

    in select_list, 100-101, 253

    @ sign, as designated escape character, 138

    attributes, 3, 388. See also column(s); fields

    diagramming, 30–31


    AVG, 100, 164–166

    AVG (DISTINCT expression), 164, 166

    — B —

    base tables, 10, 388

    BEGIN, 328

    benchmarking, 330–332, 388

    BETWEEN, 127

    to specify inclusive range, 128

    binary datatypes, 63, 388

    bit datatypes, 63, 388

    bookbiz database, 27–28, 46–49, 287

    CREATE statements, 414–427

    CREATE VIEW statements, 446–449

    database details, 379

    data entities, 29–33

    defining tables in, 66–68

    INSERT statements, 427–446

    installing, 51–52

    sample, 379–449

    table charts, 379–414

    Boolean operators, 120, 388

    AND, 121

    NOT, 124

    OR, 121–122

    braces ( { } ), 53, 54

    brackets ( [ ] ), 53, 60, 61

    business problems, 345–392

    avoiding mistakes, 370–378

    conditional thinking, 346–352

    formatting and displaying data, 353–361

    on the job uses of SQL, 345–346

    playing with patterns, 361–370

    — C —

    Cartesian product, 230–232, 388

    constraining, 233

    using, 232–233

    cascade, 342, 388

    CASE function, 346–350, 391

    CAST function, 358–360, 361, 368


    data, 83–93

    databases, 79

    table definitions, 79–81

    CHARACTER (CHAR), 62, 63, 206, 388

    character datatypes, 61, 62, 389

    character functions, 384

    character sets, 146, 389

    character strings

    matching, 134–139

    in query results, 106–107

    character values, comparing, 119

    CHECK constraints, 73, 74, 78

    compared to CREATE RULE command, 340

    in CREATE TABLE command, 340

    clustered index, 69, 71, 389

    COALESCE, 201, 351–352

    Codd, E. F., xxvii, 2, 14, 15, 16

    twelve-rule test for relational systems, 2

    COLLATE, 146

    collating sequence. See sort order

    collation, 146. See also sort order


    column(s), 3, 389

    adding, 300–301

    assigning NOT NULL to, 64–65

    assigning NULL to, 64–65

    asterisk (*) in asking for, 6

    choosing, 100–101

    all, 101–102

    specific, 102

    choosing datatypes for, 61–65

    combining, with display headings and text in SELECT list, 107

    computed, 307–308

    connecting, 205

    display headings for, 109–110

    displaying one as two, 353–356

    displaying two as one, 356–358

    DISTINCT with, 371, 372–373

    implementing constraints

    on individual, 75–77

    on multiple, 77–79

    indexes for, 69–72

    inserting data into all

    with SELECT, 86–87

    with VALUES, 84–85

    inserting data into some

    with SELECT, 88–89

    with VALUES, 85–86

    join, 205

    join-compatible, 206

    limiting the width of the display, 214–216

    rearranging result, 102–103

    specifying, 89

    column aliases, 103

    column headings, 103. See also display labels

    column names, 296–298

    computations with, 110–111

    duplicate, 297–298

    qualifying, 246–247, 248–249

    command, 5

    commas (,), 53–54, 61

    comment marks, 211, 225

    COMMIT, 328, 330

    comparison operators, 116–120, 389

    correlated subqueries with, 259–266,

    IS NULL and other, 134

    unmodified, 266

    comparisons, 381

    character values, 119

    datatypes, 382–383

    functions, 384–386

    imaginary values, 119–120

    involving NULLs, 198–199

    naming convention, 381–382

    numbers, 118–119

    complex expression, sorting by, 153

    composite indexes, 69–70, 389

    comprehensive data sublanguages, 5, 389


    with column names, 110–111

    NULLs and, 199–201

    computed columns, 307–308

    display headings for, 109–110

    concatenation, 356–358

    concurrency and transactions, 326–327

    concurrency control, 316, 390

    conditional functions, 346–352, 385

    conditions, connecting with logical operato


    Submit Errata

    More Information

    Unlimited one-month access with your purchase
    Free Safari Membership