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

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

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.

0201703092AB04062001

Description

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



0201703092B05222001

Downloads

Source Code

Click below for Source Code related to this title:
creates.zip

inserts.zip

psh4read.txt

views.zip

Sample Content

Online Sample Chapter

Practical SQL: Creating and Using Views

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:
bowmanch4.pdf

Table of Contents



Preface.


Introduction.


 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.

Preface

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.

    Acknowledgments

    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.

    0201703092P06042001

    Index

    *, 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 —

    access

    in views, 325

    permissions in, 15, 315

    strategies in, 5, 387

    Adaptive Server Enterprise, 178–179

    adding

    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 SESSION SET EVENTS command,
    388

    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

    AUTOTRACE ON, 337

    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

    changing

    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

    COLLATION FROM, 146

    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,
    269–270

    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

    computations

    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

    Updates

    Submit Errata

    More Information

    InformIT Promotional Mailings & Special Offers

    I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

    Overview


    Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

    This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

    Collection and Use of Information


    To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

    Questions and Inquiries

    For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

    Online Store

    For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

    Surveys

    Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

    Contests and Drawings

    Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

    Newsletters

    If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

    Service Announcements

    On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

    Customer Service

    We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

    Other Collection and Use of Information


    Application and System Logs

    Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

    Web Analytics

    Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

    Cookies and Related Technologies

    This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

    Do Not Track

    This site currently does not respond to Do Not Track signals.

    Security


    Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

    Children


    This site is not directed to children under the age of 13.

    Marketing


    Pearson may send or direct marketing communications to users, provided that

    • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
    • Such marketing is consistent with applicable law and Pearson's legal obligations.
    • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
    • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

    Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

    Correcting/Updating Personal Information


    If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

    Choice/Opt-out


    Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

    Sale of Personal Information


    Pearson does not rent or sell personal information in exchange for any payment of money.

    While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

    Supplemental Privacy Statement for California Residents


    California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

    Sharing and Disclosure


    Pearson may disclose personal information, as follows:

    • As required by law.
    • With the consent of the individual (or their parent, if the individual is a minor)
    • In response to a subpoena, court order or legal process, to the extent permitted or required by law
    • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
    • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
    • To investigate or address actual or suspected fraud or other illegal activities
    • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
    • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
    • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

    Links


    This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

    Requests and Contact


    Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

    Changes to this Privacy Notice


    We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

    Last Update: November 17, 2020