SQL seems to be the most neglected language when it comes to formatting nicely and readably… And as SQL statements can be incredibly detailed and complex, it makes it extremely hard to work with. But I find that when I try to format my SQL code in the best way possible I’m sometimes unsure of how to do it. I know the standards for Java, C#, Python, etc…. but when it comes to SQL I haven’t seen too many guidelines or accepted practices. What are tips/rules for formatting SQL so that it’s clear, legible, and logical? Can you give example code to illustrate? What have you found to be the most standard, accepted way of formatting SQL?
Share
You could try checking out Joe Celko’s book SQL Programming Style. I’m sure that there are a lot of people who disagree with his style, but it’s a good start.
Some of my own “rules”
For example: