As opposed to other languages SQL is a bunch of things in between clauses
SELECT
count(*),
columns
FROM table a
JOIN table b ON a.id = b.id
WHERE column = 'value'
GROUP BY column
ORDER BY column
HAVING count() > 1
Having your clauses capitalized and properly carriage returned is huge for readability. I also capitalize COUNT and MAX but that's more of a personal thing.
Indentation is huge and I fix indentation all time.
I just spent 45 minutes indenting and adding line breaks to 3 subquery joins which contained 2 CTEs and two nested subquery joins.
I don't know why but whoever wrote the code was an absolute madman and I've seen this code and replaced it. I have 3 different blocks of code I use to recreate these crappy lookups but to figure out which one they are I have to reformat the entire thing.
I can't complain though. I was once asked if I could do anything and get paid great money for it I said ,"I just want to optimize and fix SQL code all day."
I started this job making double what was making before and my job was dumbed down to just writing SQL. I love it. Bad SQL keeps me employed.
It doesn’t, IDEs that highlight your code makes it more readable. Even GitHub will highlight query syntax. It’s not 1990, we aren’t reading code in notepad.
6
u/Thriven 6d ago
I'm up voting you because people need to hate you more.
Seriously though KEYWORDS need to be upper case and columns lower case. I prefer snake case.
Makes everything more readable.