I have often seen the queries written in SQL in CAPITAL LETTERS. Though I think SQL is not case sensitive, why do most of them prefer to write in CAPITAL LETTERS ? Is it just a matter of choice or does it have some logic?
-
2possible duplicate of [Why are MySQL queries almost always written in Capital](http://stackoverflow.com/questions/9325927/why-are-mysql-queries-almost-always-written-in-capital) – Sudhir Bastakoti Feb 24 '12 at 06:00
-
42IF YOU WRITE YOUR QUERIES LIKE THIS THE SERVER WILL HEAR THEM BETTER AND EXECUTE THEM BEFORE quieter queries, written like this. At least that's what I think, and why my queries are mostly written in capital letters. – ta.speot.is Feb 24 '12 at 06:02
-
1possible duplicate of [Lowercase or uppercase for SQL Statements](http://stackoverflow.com/questions/7566164/lowercase-or-uppercase-for-sql-statements) – Druid Aug 01 '12 at 09:36
-
Given they are not needed and reading them is known to be harder to read - https://www.mity.com.au/blog/writing-readable-content-and-why-all-caps-is-so-hard-to-read - I would encourage ditching the ALLCAPS convention entirely. – Tim Abell Mar 04 '21 at 10:04
7 Answers
It was meant for readability. Before, SQL was written in plain-text editors (no syntax/code highlighting) and keywords needed to be differentiated for better readability and maintenance.
SELECT column_name
FROM table_name
WHERE column_name = column_value
vs
select column_name from table_name where column_name = column_value
See the difference? The first word in each line told the reader exactly what was going on (selecting something from somewhere where something).
But now with syntax-highlighting, there's really no point. But it IS a best practice and allows SQL developers to be on the same page/style while developing.
- 2,819
- 19
- 19
It varies with when you learned SQL and who or where you learned it from.
It originated on IBM mainframes and those definitely preferred upper-case.
These days, I write the keywords in all-caps and the database objects in either lower-case or in SuitablyMixedCase. That simply makes it easy to see the keywords, while leaving the important information (table names, column names, etc) in more readable mainly lower-case letters. It makes it trivial to read past the keywords.
Of course, I've been writing SQL for...ulp...over twenty-five years, so lots of stuff like this is simply 'second nature' and 'the way I've always done it'. But I find it makes for more readable SQL.
- 698,132
- 130
- 858
- 1,229
SQL is a case insensitive programming language, whether u write in CAPITAL or not it will not affect your logic. It is basically done to increase the readability of SQL Query
- 35
- 1
- 8
-
Thats what the Exact Duplicate Question's Answer says, so what different is your answer...! – Sudhir Bastakoti Feb 24 '12 at 06:03
-
1
Entry level SQL:1992 is case sensitive and requires that identifiers (SQL keywords) are in upper case only. Or should I say "required": case insensitive identifiers has been a core standard feature since SQL:1999. I would guess that upper case keywords was the vernacular for programming language design in the late sixties/early seventies.
Nowadays putting SQL keywords in upper case is merely a matter of taste and is my personal preference. I agree that it aids readability and this is why I use lower case for attribute names (with underscore element separators e.g. birth_date) and upper camel case for table names. Not coincidentally, these are the recommended conventions in the only book on SQL heuristics, Joe Celko's SQL Programming Style.
- 53,058
- 12
- 94
- 134
It's for readability. If we didn't have colored keywords, CAPS would allow us to distinguish keywords.
- 4,689
- 1
- 27
- 39
There is no real purpose to it, it is simply a choice of style or convention. It wouldn't affect your them either way, personally I keep all of mine lower case.
- 10,902
- 11
- 61
- 113
SQL compiler translates the query written by use to upper case before compiling, It's good to write it in upper case for fast processing
- 1
-
_write it in upper case for fast processing_ can you please justify this? – serenesat Aug 03 '15 at 09:08