Bill Karwin has helped thousands of people write better SQL and build stronger relational databases. Now he’s sharing his collection of antipatterns—the most common errors he’s identified in those thousands of requests for help.

Most developers aren’t SQL experts, and most of the SQL that gets used is inefficient, hard to maintain, and sometimes just plain wrong. This book shows you all the common mistakes, and then leads you through the best fixes. What’s more, it shows you what’s behind these fixes, so you’ll learn a lot about relational databases along the way.

Buy Now

Select a DRM-free Format:

In Stock
In Stock
In Stock
Buy the eBook and get these DRM-free formats delivered immediately:
  • epub (for iPhone/iPad, Android, eReaders)
  • mobi (for Kindle)
  • PDF
We can automatically send them to your Dropbox. (You'll need to log in to enable these options.)

About this Book

  • 328 pages
  • Published:
  • Release: P4.0 (2014-08-08)
  • ISBN: 978-1-93435-655-5

Each chapter in this book helps you identify, explain, and correct a unique and dangerous antipattern. The four parts of the book group the antipatterns in terms of logical database design, physical database design, queries, and application development.

The chances are good that your application’s database layer already contains problems such as Index Shotgun, Keyless Entry, Fear of the Unknown, and Spaghetti Query. This book will help you and your team find them. Even better, it will also show you how to fix them, and how to avoid these and other problems in the future.

SQL Antipatterns gives you a rare glimpse into an SQL expert’s playbook. Now you can stamp out these common database errors once and for all.

Whatever platform or programming language you use, whether you’re a junior programmer or a Ph.D., SQL Antipatterns will show you how to design and build databases, how to write better database queries, and how to integrate SQL programming with your application like an expert. You’ll also learn the best and most current technology for full-text search, how to design code that is resistant to SQL injection attacks, and other techniques for success.

Contents and Extracts

Full Table of Contents


  • Logical Database Design Antipatterns
    • Jaywalking
    • Naive Trees excerpt
    • ID Required
    • Keyless Entry
    • Entity-Attribute-Value
    • Polymorphic Associations
    • Multi-Column Attributes
    • Metadata Tribbles
  • Physical Database Design Antipatterns
    • Rounding Errors
    • 31 Flavors
    • Phantom Files
    • Index Shotgun
  • Query Antipatterns
    • Fear of the Unknown
    • Ambiguous Groups
    • Random Selection excerpt
    • Poor Man’s Search Engine
    • Spaghetti Query
    • Implicit Columns
  • Application Development Antipatterns
    • Readable Passwords
    • SQL Injection excerpt
    • Pseudokey Neat-Freak
    • See No Evil
    • Diplomatic Immunity
    • Magic Beans
  • Appendixes
    • Rules of Normalization
    • Bibliography

About the Author

Bill Karwin has been a software engineer for over twenty years, developing and supporting applications, libraries, and servers such as Zend Framework for PHP 5, the InterBase relational database, and the Enhydra Java application server. Throughout his career, Bill has shared his knowledge to help other programmers achieve success and productivity. Bill has answered thousands of questions, giving him a unique perspective on SQL mistakes that most commonly cause problems.

Comments and Reviews

  • Ask Felgall said:

    A ‘must have’ book for anyone writing SQL who hasn’t done an SQL course and very useful even if you have.

  • Desicritics said:

    I would highly recommend it to anyone who is interested in a good list of do’s and don’ts of database programming, explained clearly and with precise examples that relate very well to real-world examples.

  • Data and Technology Today said:

    SQL Antipatterns should become a useful tool for DBAs and database programmers to help them create well-designed databases and applications…and to help us eliminate these common errors from our database implementations.

  • This book is obviously the product of many years of practical experience with SQL databases. Each topic is covered in great depth, and the attention to detail in the book was beyond my expectations. Although it’s not a beginner’s book, any developer with a reasonable amount of SQL experience should find it to be a valuable reference and would be hard-pressed not to learn something new.

    —Mike Naberezny Partner at Maintainable Software; Coauthor of "Rails for PHP Developers"
  • Arjen Lentz said:

    I really like how Bill has approached this book; it shows his unique style and sense of humor. Those things are really important when discussing potentially dry topics. Bill has succeeded in making the teachings accessible for developers in a good descriptive form, as well as being easy to reference later. In short, this is an excellent new resource for your pragmatic bookshelf!

    Executive Director of Open Query
  • Bill has written an engaging, useful, important, and unique book. Software developers will certainly benefit from reading the antipatterns and solutions described here. I immediately applied techniques from this book and improved my applications. Fantastic work!

    —Frederic Daoud Author of "Stripes: ...And Java Web Development Is Fun Again" and "Getting Started with Apache Click"
  • I am a strong advocate of best practices. I prefer to learn from other people’s mistakes. This book is a comprehensive collection of those other people’s mistakes and, quite surprisingly, some of my own. I wish I had read this book sooner.

    —Marcus Adams Senior Software Engineer