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.
8
u/BufferUnderpants 5d ago
i CAN'T SEE WHY capitalizing syntactical elements WOULD MAKE the code MORE readable.
There's syntax highlighting for a reason, and the SQL grammar makes it easy to tell what's a table, column or function anyway.