-2

Almost any literature writes SQL keywords and functions in UPPERCASE. e.g.

SELECT column_1, MAX(column_b), * FROM table AS alias;
  • What is the reason for this?
  • Is it because of a better readability?
  • Is it considered bad habit to write code in lowercase? e.g.
select column_1, max(column_b), * from table as alias;

What coding style should I use for SQL and why?

0

1 Answer 1

5

What is the reason for this?

When SQL was invented, the dominant programming languages were using uppercase for keywords.

Also, there were no syntax-highlighting IDEs back then.

Is it because of a better readability?

This is ultimately matter of preference. Many will find that more readable. But if you are using IDE, it will highlight the keywords for you, so it doesn't matter that much.

Only situation where you'll get clear improvements to readability is when you are composing SQL commands as strings, where the IDE will not highlight the keywords. E. g.

var sqlCommand = "SELECT Name FROM MyTable WHERE Id = @id;";

vs

var sqlCommand = "select Name from MyTable where Id = @id;";

Is it considered bad habit to write code in lowercase?

Not really, but your team might have preference about this.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.