16

I've seen most coders use Capital letters while writing MySQL queries, something like

 "SELECT * FROM `table` WHERE `id` = 1 ORDER BY `id` DESC"

I've tried writing the queries in small caps and it still works.

So is there any particular reason for not using small caps or is it just a matter of choice?

ptamzz
  • 8,835
  • 31
  • 88
  • 144

4 Answers4

12

It's just a matter of readability. Keeping keywords in upper case and table/column names lower case means it's easier to separate the two when scan reading the statement .: better readability.

Most SQL implementations are case-insensitive, so you could write your statement in late 90s LeEt CoDeR StYLe, if you felt so inclined, and it would still work.

Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
  • 1
    There's many times I've been reviewing others code and instances where they've specified keywords in lowercase has resulted in issues being missed due to skimming over large volumes of text. Sticking to a standard of having all keywords in upper case prevents that as everyone involved is able to scan for them easily. – Simon at My School Portal Feb 17 '12 at 09:45
  • Case insensitivity is not limited to MySQL. Most of the SQL engine are case insensitive. – Sylvain Defresne Feb 17 '12 at 09:52
  • I think the SQL standard specifies case-insensitivity. – Donal Fellows Feb 17 '12 at 10:02
  • "Most SQL implementations"? Are you sure that this shouldn't be "all"? The answer would be better if you could be specific about this insensitivity being part of the standard or not; if it's not, then an example of a still standard-compliant SQL implementation which is not insensitive would be great; if it is, then this should be stated clearly. – Alfe Jul 20 '16 at 15:52
1

The case make no difference of the SQL engine. It is just a convention followed, just like coding conventions use in any of the programming languages

Sunil Kumar B M
  • 2,637
  • 1
  • 22
  • 31
1

You have to have a system - there are already a few questions on the site that deal with conventions and approaches. Try:

SQL formatting standards

Community
  • 1
  • 1
lap
  • 198
  • 1
  • 7
0

This is for readability sake.

Sometimes we have to write queries like that because our project (official) recommends.

But everything for readability and uniformity in a project.

Balaswamy Vaddeman
  • 8,000
  • 3
  • 29
  • 40