News for hackers. Stuff that matters.
Re:Writing more legible SQL by lost_my_pwd on Thursday November 03, 2016 @06:44AM (#12862798)
That matches what I do pretty much with the exception of capitalization. I agree, it's not totally necessary, but it does provide a visual delineation of each section/component of the the statement, which, for large statements, can be very helpful in quickly scanning what it does:

    SELECT
        t1.col1,
        t2.col2,
        t3.col3

    FROM
        table1 t1
        join table2 t2 on t1.col2 = t2.col1
        join table3 t3 on
            t1.col3 = t3.col1 and
            t3.col2 = something_else

    WHERE
        t1.col1 > 0 and
        t2.col2 <> t1.col4

    ORDER BY col2
    LIMIT 100
    ;
Re:Writing more legible SQL by mozumder on Thursday November 03, 2016 @06:49AM (#12862810)
The lower-case probably works better for IDEs that have SQL syntax-coloring. If your IDE doesn't have that (looking at you XCode..), then upper-case keywords are better.
Re:Writing more legible SQL by bluedino on Thursday November 03, 2016 @07:37AM (#12863092)
>> If your IDE doesn't have that

I'm looking at you, System i Navigator. Also you don't support anti-aliased fonts or scale properly (because you're a 90's Java application)

Re:Writing more legible SQL by biztos on Thursday November 03, 2016 @10:32AM (#12864207)
I do almost the same thing, but I capitalize all SQL keywords. I'm sure that's annoying to someone somewhere but I find it useful in separating the SQL from the relation names.
Re:Writing more legible SQL by WorldMaker on Thursday November 03, 2016 @05:11PM (#12867990)
We've had great syntax highlighting tools for decades now, I'd much rather my tooling do it for me with subtle colorations than be forced to resort to COBOL SCREAMING.

I've trended towards a preference to "sentence-cased" SQL where the first word in an SQL statement is Capitalized and everything else is lower-cased. Makes things read more like a narrative and is a nicer hint than trying to spot an optional semi-colon to determine if you've reached the end of a command yet (and helps in those times when you need to find a place where it turned out an optional semi-colon wasn't in fact optional).

    Select *
    from table
    where condition
    order by fields

    Insert into table
      (...)
    values
      (...)
So far as I know I'm about the only person that likes sentence-casing SQL, but it helped me out quite a bit on some projects I worked on and it kept things readable.
Re:Writing more legible SQL by specialist on Thursday November 03, 2016 @09:12AM (#12863634)
+1 Vertical whitespace.
Re:Writing more legible SQL by gbog on Thursday November 03, 2016 @10:41AM (#12864290)
yes, neat, and yes SQL is code. Problem is that there is not SQL linter I know of.