Possible Duplicate:
Is there a good reason to use upper case for T-SQL keywords?
Simple question. I personally find a string of lowercase characters to be more readable than a string of uppercase characters. Is some old/popular flavor of SQL case-sensitive or something?
For reference:
select
this.Column1,
case when this.Column2 is null then 0 else this.Column2 end
from dbo.SomeTable this
inner join dbo.AnotherTable another on this.id = another.id
where
this.Price > 100
vs.
SELECT
this.Column1,
CASE WHEN this.Column2 IS NULL THEN 0 ELSE this.Column2 END
FROM dbo.SomeTable this
INNER JOIN dbo.AnotherTable another ON this.id = another.id
WHERE
this.Price > 100
The former just seems so much more readable to me, but I see the latter way more often.
One thing I'll add to this which I haven't seen anyone bring up yet:
If you're using ad hoc SQL from within a programming language you'll have a lot of SQL inside strings. For example:
In this case syntax coloring probably won't work so the uppercasing could be helping readability.
Apropos of nothing perhaps, but I prefer typesetting
SQL
keywords in small caps. That way they look capitalized to most readers, but they aren't the same as the ugly ALL CAPS style.A further advantage is that I can leave the code as is and print it in the traditional style. (I use the
listings
package inLaTeX
for pretty-printing code.)I like to use upper case on SQL keywords. I think my mind skips over them as they are really blocky and concentrates on what's important. The blocky words split up the important bits when you layout like this:
(The lack of ANSI joins is an issue for another question.)
There is a psychology study that shows lowercase was quicker to read than uppercase due to the outlines of the words being more distinctive. However, this effect can disappear about with lots of practice reading uppercase.
I prefer using upper case as well for keywords in SQL.
Yes lower case is more readable but for me having to take extra second to scan through the query will do you good most of the time. Once it's done and tested you should rarely ever see it again anyway (DAL, stored proc or whatever will hide it from you).
If you are reading it for the first time, capitalized WHERE AND JOIN will jump right at you, as they should.
Code has punctuation which SQL statements lack. There are dots and parentheses and semicolons to help you keep things separate. Code also has lines. Despite the fact that you can write a SQL statement on multiple physical lines, it is a single statement, a single "line of code."
IF i were to write english text without any of the normal punctuation IT might be easier if i uppercased the start of new clauses THAT way itd be easier to tell where one ended and the next began OTHERWISE a block of text this long would probably be very difficult to read NOT that id suggest its easy to read now BUT at least you can follow it i think
I think the latter is more readable. You can easily separate the keywords from table and column names, etc.