small medium large xlarge

SQL Antipatterns: Avoiding the Pitfalls of Database Programming


Cover image for SQL Antipatterns

SQL Antipatterns

Avoiding the Pitfalls of Database Programming


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.

Customer Reviews

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

- Ask Felgall

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.

- Desicritics

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.

- Data and Technology Today

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"

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!

- Arjen Lentz

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

See All Reviews

Choose Your Format(s)

  • $25.00 In Stock
  • Ebooks are DRM free.

  • Ebook delivery options.

Contents & 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


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.