Uppercase or lowercase T-SQL keywords


I have been rethinking using uppercase letters for T-SQL keywords. Readability research shows that uppercase keywords are harder to read and experience shows they are harder to type. Is it just tradition that keeps T-SQL developers uppercasing keywords?


 


After searching the internet, the only argument I found for uppercasing keywords is the traditional one that it makes keywords easier to discern from other constructs. However, the days of green screen terminals are long gone. Modern T-SQL editors automatically color code various language constructs so using case to do it seems an unnecessary and harmful step.


 


All this would be just an idiosyncratic preference of some Microsoftie but I am thinking about the formatting options and defaults for automatically generated T-SQL. Any feedback is welcome.  


 


This posting is provided “AS IS” with no warranties, and confers no rights.


 


Comments (10)

  1. codputer says:

    It would be great if we could create a template that would format automatically generated T-SQL statements. In my past applications the T-SQL generated for ACID statemnts for the dataadapter would always need to be reformatted (line one column per row, and indented under the select statement)

  2. codputer says:

    While I’m at it, why do we always have to put comments intermixed with code? With the horsepower of our development machines today, I would rather type comments on another "layer" in the editor UI. Hit a button, and type (or how about ink) on a "veil" that was maintained on another layer. That way the compiler would never see comments, as it would only read the "code layer". I realize that there a many considerations (like a line insert!), but I’m pretty sure the abilty to maintain separate layers would give the UI more ability and capability to be creative in comments, while still allowing only code to be send to the compliler.

  3. Jeff Parker says:

    I think I started off my programming against t-sql pretty much doing it First Character Upper case lower case everything else. Lately though since .net I have been using upper case more. Especially when I have my sql command and dynamic parameters set in code. For me it is more readable. Since even in VS a string is a string and is only one color. Every not and then I still slip and it is camel cased, but I do still find it easier to read when the SQL Command are all Upper cased.

  4. rprimrose says:

    I still find upper case reserved words easy to read.

    The color argument is a valid one, but you aren’t always working in an application that supports it. For example, when you copy/paste the code to web sites or other documents (even notepad), that color support isn’t always transfered.

    Another example is when you export scripts in Yukon (up to the June CTP), they are exported as strings that will be executed, therefore all words are green. The same goes for building dynamic SQL statements to execute (evil as it is :P).

  5. Matthew says:

    > Readability research shows that uppercase keywords are harder to read

    Those studies are probably to do with standard text, rather than programming languages.

    I suspect that uppercase keywords in SQL make the text easier to read, since they highlight the inherent structure of SQL (natual language lacks this ‘inherent structure’).

  6. Yurko says:

    I wrote program which ease you of UpperCase SQL keywords. It trasforms all keywords you type to uppercase on the fly.

    You can read about it here: http://sql.yurko.ru

  7. Julie Green says:

    When do I use upper case or lower case when referring to mother and father?

  8. Michael says:

    Hi,

    Having used various 4GLs for quite a few years before getting into SQL Server coding, I find thatthe most readable code is gained by putting keywords into lower case and table/columnnames into upper case.

    We all know what the relatively common main keywords in T-SQL mean and where they fit into a block, particularly if we format uisng indentation consistently.  

    What really distinguishes one block of code from another within more complex stored procedures or functions is the Table and Columns which are the subject of the relatively common T-SQL syntax.  My experience is that the names and columns are what really need emphasising in the code.

    Just my few pennies worth..

    Michael

  9. Lance says:

    I agree with Micheal, after looking at enough T-SQL with both keyword in UPPER and lower case, it is a lot easier to read when it's lower case