4

I read a bunch of the articles a questions asking about capitalizing SQL keywords (SELECT, FROM, WHERE, etc.), but I couldn't find a thread for the following:

Should I capitalize SQL functions, like SUM(), COUNT(), etc.? The teacher of a class I took used to capitalize the functions, but a software engineer at work told me not to.

Is there a convention?

Leon S
  • 153
  • 1
  • 13
  • All caps is harder on the eye. Coding standards are mostly arbitrary though. While there are benefits to consistency and formatting, it's a refrain of spoiled, lazy whiners to gripe about it too much. You question is probably going to be downvoted as not having an objective answer. – shawnt00 Aug 28 '19 at 17:02

4 Answers4

4

In short, it really comes down to personal preference/style. It's a traditional convention that's been around for ages to always use upper case letters for reserved words in SQL (see here: https://www.sqlstyle.guide/#query-syntax) and the idea is that even if someone is not using an IDE that highlights the reserved words, they can still easily differentiate between the reserved keywords and other stuff such as column and table names.

Personally, I think capitalizing the reserved words just makes the SQL code look like it's from 30 years ago and constantly using shift or caps lock while typing is just not something I want to do. There are auto-formatting extensions that you can use but honestly...why?

samredai
  • 662
  • 3
  • 8
2

I use SQLPrompt extension which corrects what you type to UPPER case when needed by convention.

Yes, COUNT(), SUM() and other functions are capitalized by SQL Prompt.

tgralex
  • 794
  • 4
  • 14
2

Yes, capitalizing SQL statements is a convention and I strongly suggest to use it. Like others wrote in this thread it really helps with reading scripts (you will see that they can be really big).

T-SQL conventions from MS: link

Beniamin Makal
  • 164
  • 1
  • 5
1

From what I've seen it is personal preference, but it will have no effect on how your query runs. I do because I think it makes the query more readable, but if your team does not want you to then you shouldn't.

ZzZylo
  • 31
  • 5