• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!


sql antipatterns: avoid the pitfalls of database programming

This version was saved 5 years, 3 months ago View current version     Page history
Saved by Nathan T Suver
on March 10, 2019 at 9:20:55 am


If you're programming applications that store data, then chances are you're using SQL, either directly or through a mapping layer. Well, here's a sad secret - most developers aren't SQL experts, and most of the SQL that gets used is inefficient, hard to maintain, and sometimes just plain wrong.



B. Karwin, SQL Anti-patterns Avoiding the Pitfalls of Database Programming, The Pragmatic Bookshelf, 2010.


Relevant Quotes:

(page 205)

Antipattern: Solve a Complex Problem in One Step SQL is a very expressive language—you can accomplish a lot in a single query or statement. But that doesn’t mean it’s mandatory or even a good idea to approach every task with the assumption it has to be done in one line of code. Do you have this habit with any other programming language you use? Probably not.


The Law of Parsimony When you have two competing theories that make exactly the same predictions, the simpler one is the better 


Writing SQL Automatically—with SQL When you split up a complex SQL query, the result may be many similar queries, perhaps varying slightly depending on data values. Writing these queries is a chore, so it’s a good application of code generation. Code generation is the technique of writing code whose output is new code you can compile or run. This can be worthwhile if the new code is laborious to write by hand. A code generator can eliminate repetitive work for you.





Comments (0)

You don't have permission to comment on this page.