THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Denis Gobo

SQL Controversy: Capitalizing Keywords

Do you write code like this?

set ROWCOUNT 10
select Products.ProductName as TenMostExpensiveProducts, Products.UnitPrice
from Products
order by Products.UnitPrice desc

Or like this?

SET ROWCOUNT 10
SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC


Do we need to capitalize the keywords, functions and statements when we have syntax coloring built into the product?
Look if you use SPUFI with DB2 I understand (see image below)





Here is another example this time without color.


set ROWCOUNT 10
select Products.ProductName as TenMostExpensiveProducts, Products.UnitPrice
from Products
order by Products.UnitPrice desc


SET ROWCOUNT 10
SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC

And yes I agree the bottom query is much easier to read

But with syntax coloring do you still need this? It is a big pain in the neck to use that CapsLock/Shift key every time you type a keyword. There are tools of course like SQL Formatter which will make it much easier. 
Remember Hungarian notation, In VB you would write sLastName(string), iCounter(integer)? Well that is gone also, who needs it when you have IntelliSense?
I think the lowercase sql code is easier on the eyes. So what do you think?

Published Monday, July 09, 2007 12:11 PM by Denis Gobo
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Ranga said:

i prefer lower case...agree, lower case is easier on the eyes..

July 9, 2007 12:42 PM
 

MattK said:

What if you are using another editor, that does not colorize syntax? Printing to a B&W printer?

Case and whitespace are persistent formatters across all tools and display methods, but colorization is not always available.

July 9, 2007 1:32 PM
 

Hugo Kornelis said:

I have to agree with MattK. I write a lot of my queries in notepad, so I really need the uppercased keywords to keep the query readable.

Not to mention the many posts I make in usenet groups that contain snippets of SQL but no color anywhere.

July 9, 2007 2:26 PM
 

Denis Gobo said:

I admit when writing 'production code' I will use the capitalized syntax

Take a look here

http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl

That is a good tool to keep open for newsgroup replies, but then again I don't capitalize my replies either

July 9, 2007 3:07 PM
 

Claude said:

CAPS ALL THE WAY (For keywords that is)

July 10, 2007 10:24 AM
 

Don said:

For the 12 years I have use CAPS for SQL key words.  Just this year, I did a top to bottom review of our SQL Standards and this was one of the things that we discussed quite a bit.  Until then, I had just taken CAPS as gospel, but when it came right down to it, we concluded that the time and effort to keep hitting the caps lock key just couldn't be justified any longer.

I have to say that despite my initial discomfort with the change, I really don't miss capitalizing key words, and in the last 6 months, I haven't run into a single instance where I wished that we hadn't made the switch.

July 12, 2007 9:32 AM
 

SSQA.net said:

I prefer mixed case for table columns but for keywords CAPITALS good to go.

July 13, 2007 9:29 AM
 

Anz said:

I use CAPITALS for keywords

July 15, 2007 11:27 PM
 

DJS said:

Personally I think the arrangement of clauses is more important for formatting than the case of keywords. I’m constantly amazed at how poorly various tools are at this. It is almost like they are trying to make it hard to read. For example here is a query created in Sql Management Studio’s Query Designer.

SELECT     Main.ID, Child.ID, Main.SSN, Main.LName, Main.FName, Main.DOB

                     Main.MI, Child.ID, Child.IsActive, Codes.ID, Codes.Code, Codes.Description

FROM         Main INNER JOIN

                     Child ON Main.ID = Child.MainID INNER JOIN

                     Codes ON Child.Code = Codes.Code

WHERE Month(Main.DOB) = Month(GETDATE()) AND Child.IsActive = 1

This query seems like it was written by a scatter brain after 6 shots of espresso. Below is the same query formatted with the web site mentioned above.

Select Main.ID,

      Child.ID,

      Main.SSN,

      Main.LName,

      Main.FName,

      Main.DOB Main.MI,

      Child.ID,

      Child.IsActive,

      Codes.ID,

      Codes.Code,

      Codes.Description

From   Child

      Inner Join Main

        On Child.MainID = Main.ID

      Inner Join Codes

        On Child.Code = Codes.Code

Where  Month(Main.DOB) = Month(GETDATE())

And Child.IsActive = 1

The key for me is the From clause and Join clauses. They are clearly distinct and easy to read with their corresponding On qualifiers. Why can’t Microsquish understand how useful a clear formatting would be to programmers?

Perhaps this would be an appropriate discussion for another post.

July 18, 2007 8:19 AM

Leave a Comment

(required) 
(required) 
Submit

About Denis Gobo

I was born in Croatia in 1970, when I was one I moved to Amsterdam (and yes Ajax is THE team in Holland) and finally in 1993 I came to the US. I have lived in New York City for a bunch of years and currently live in Princeton, New Jersey with my wife and 3 kids. I work for Dow Jones as a Database architect in the indexes department, one drawback: since our data goes back all the way to May 1896 I cannot use smalldates ;-( I have been working with SQL server since version 6.5 and compared to all the other bloggers here I am a n00b. Some of you might know me from http://sqlservercode.blogspot.com/ or even from some of the newsgroups where I go by the name Denis the SQL Menace If you are a Tek-Tips user then you might know me by the name SQLDenis, I am one of the guys answering SQL Questions in the SQL Programming forum.

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement