Personally, given SQL's intended similarity to English, I find that I like English "sentence case" for it, with the opening keyword starting with a capital letter and nearly every remaining letter lower case (except for Proper Nouns, the truly case-sensitive parts of SQL like table names). Sentence case has been helpful to me in the past in spotting things like missing semicolons in dialects like Postgres' that require them, and/or near keywords like `Merge` that require them or helping to visually make sure the `select` under a `Merge` is intended as a clause rather than starting a new "sentence".
I could go either way, but if you want to go back and modify a query, this makes it more difficult for me. I just use a block syntax for my queries:
SELECT *
FROM the_table
WHERE some_column = 12
AND other_column IS NOT NULL
ORDER BY order_column; Select *
from the_table
where some_column = 12
and other_column is not null
order by order_column;
That seems so much more readable to me. As I said, that single capital `S` in the outermost "select" has come in surprisingly handy in my experience when scanning through a collection of statements or a transaction or a stored procedure or even just a statement with a bunch of nested sub-selects. It's an interesting advantage I find over "all lower case" or "all upper case" keywords.the other example has the commands, in caps, on the left and the values on the right, in lowercase. your example removes one of those aspects and makes everything lowercase. my brain can ignore all-caps stuff, as these are just commands and the things i actually care about mostly are the values.
but i mean, in the end, it's just preferences. if you write SQL-queries, #1 is that you understand them well :)
Agree, but I wonder how much of that is just the lack of colouring. My brain is suuuuper hard wired to expect all the special keywords to be identified that way as well as by case.
Mostly I'm a caps guy because my ahk scripts expand text like "ssf","w" and "gb"* to be the way I learned to write them at first.
SELECT *
FROM the_table
WHERE some_column = 12
AND other_column IS NOT NULL
ORDER BY order_column;
I usually don't bother with ALL-CAP keywords. SELECT
a,
b
FROM t1
JOIN t2 ON …
WHERE cond1
AND cond2
ORDER/GROUP/HAVING etc