views:

1090

answers:

11

The default seems to be upper case but is there really any reason to use upper case for keywords? I started using upper case because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored procedure. But then, I feel terrible for my baby (5th) finger that always needs to hold down the SHIFT button so I stopped using upper case. Any reason why I should go back to upper case?

Edit: Thanks for the answers guys. I wasn't programming yet back in the days when COBOL was king so I wasn't aware of this. I'll stick with lower case from now on.

+12  A: 

It's just a matter of style, probably originating in the days when editors didn't do code colouring.

I used to prefer all upper case, but I'm now leaning towards all lower.

Mitch Wheat
+1 I guess I wasn't the only one using all lowers for keywords.
Sung Meister
I'd go with the assumption that it hoes back to the days when editors didn't do code colouring.
Benjol
A: 

I think it stems from legacy systems. Parts of DB2 and COBOL, for example, are case sensitive. Resultantly, legacy DBA's and mainframe developers would just name things in all caps, which proceeded to just typing in all caps.

'course that's just how I see it, as the old crusty mainframers are the only ones I see doing it anymore.

tsilb
+1  A: 

Upper case can provide a gain in keyword visibility, but you can compensate with code highlight and indentation.
We use lower case because query editor and other tools do wonders in editing t-sql code, and we see no need to torture the little finger.

Ovidiu Pacurar
+2  A: 

Monkey see, monkey do for me. Pattern matching - if I do it the way I've seen it done, the structure of the clauses lines up mentally more easily.

le dorfier
+2  A: 

I find it more readable. Same for having a newline for the beginning of each clause and indenting between clauses.

MarkB
+3  A: 

Try a formatting product (I use SQL Prompt/SQL Refactor from Red Gate). You can set how you want the capitalization to work, and your code will always be consistently formatted. Rest your pinky and let the computer do the work for you.

gfrizzle
A: 

Other than conformity for conformitys sake, no. Although it's a very subjective topic, I prefer using mixed case for all SQL. The SQL is much easier to read, and nothing is lost in modern IDEs where keywords are all color-coded anyway.

Charles Bretana
A: 

One of the reasons for continuing to use capitalization is when you(or someone else) are viewing code in something like notepad, it makes it easier to read. i.e. you can differentiate easily between the "keywords" and the tablenames, SP's, udf's etc

UndertheFold
+5  A: 

PERSONALLY, I DON'T LIKE MY SQL YELLING AT ME. IT REMINDS ME OF BASIC OR COBOL.

So I prefer my T-SQL lowercase with database object names MixedCase.

It is much easier to read, and literals and comments stand out.

Gordon Bell
It is so much a matter of taste. In my experience, the amount of yelling is not too great -- I prefer the upper-case keywords because it is much easier to read and literals and comments stand out.
Jonathan Leffler
+1 for "I DON'T LIKE MY SQL YELLING AT ME"
Sung Meister
+6  A: 

Gordon Bell's examples are not exactly correct; generally, only the keywords are highlighted, not the entire query. His second example would look like:


SELECT name, id, xtype, uid, info, status, 
base_schema_ver, replinfo, parent_obj, crdate, 
ftcatid, schema_ver, stats_schema_ver, type, 
userstat, sysstat, indexdel, refdate, version, 
deltrig, instrig, updtrig, seltrig, category, cache
FROM sysobjects
WHERE category = 0
AND xtype IN ('U', 'P', 'FN', 'IF', 'TF')
ORDER BY 1

I find this far easier to read, since the keywords stand out more. Even with syntax highlighting, I find the uncapitalized example much harder to read.

At my company, we go a little bit farther with our SQL formatting.


SELECT      name, id, xtype, uid, info, status, 
      base_schema_ver, replinfo, parent_obj, crdate, 
      ftcatid, schema_ver, stats_schema_ver, type, 
      userstat, sysstat, indexdel, refdate, version, 
      deltrig, instrig, updtrig, seltrig, category, cache
FROM sysobjects
LEFT JOIN systhingies ON
    sysobjects.col1=systhingies.col2
WHERE category = 0
    AND xtype IN ('U', 'P', 'FN', 'IF', 'TF')
ORDER BY 1
notJim
Yea, that is how I like it too.
David The Man
+2  A: 

Uppercase is less readable. The outline of all words are shaped like boxes; there are no descenders or ascenders. Lowercase FTW!

Lance Fisher