Lesson 65. Why People That Indent Code Drive Me Nuts
(AKA A Recommended SQL Style Guide)
I am that rare breed of human for whom SQL is my primary language. Of course, I had learned other programming languages prior to SQL, but I never used them day in and day out. Most people come to SQL from other programming languages and they have a tendency to bring their nonsense with them.
This is a personal pet peeve. SQL is not like Python which enforces indentation and spacing between lines of code. People that come from other languages try to overlay whatever coding standard they have previously used onto SQL. What you wind up with is a mishmash of code inconsistently flowing all over the place as the individual engineer interprets where THEY think indents should go. Contrary to popular belief, this does NOT result in more readable code. If you left justify all of your code, at least you can use that as a universal coding standard that everybody has to follow.
Below are my recommendations for a SQL style guide. I use and implement these standards everywhere I go.
Left justify your code. Every character of every line should start at column 1 in the editor.
Capitalize SQL syntax.
If you have a really long line of code, let it run off the page. Who cares? That’s what the scroll bar is for.
If you have a lot of columns in your select statement, give each column its own row.
”Drop if exists” should be a part of every script that creates a permanent database object.
Examples
Old Man Yells At Cloud
Left justify your code. Every character of every line should start at column 1 in the editor. Go back and look! This entire tutorial follows that standard.
In [ ]:
Capitalize SQL syntax.
In [ ]:
If you have a really long line of code, let it run off the page. Who cares? That’s what the scroll bar is for.
Note: This is a contrived example. As you can see, it CLEARLY violates standard 4.
In [ ]:
If you have a lot of columns in your select statement, give each column its own row.
In [ ]:
”Drop if exists” should be a part of every script that creates a permanent database object.
In [ ]:
Last updated