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?
Keywords in SQL are case-insensitive for the most popular DBMSs. The computer doesn't care whether you write SELECT , select, or sELeCt ; so, in theory, you can write however you like.
Capitalizing those keywords helps you visually separate the separate clauses. This is especially handy when in one of those tricky debugging situations where you're outputting your SQL in an HTML comment, then copy-pasting into a console.
Table names are stored in lowercase on disk and name comparisons are not case-sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
No, by default, SQL is not case-sensitive. Whenever you see capitalized letters in SQL queries it's because of a naming convention. Your query would run just the same even if you write your SQL keywords in all caps or not.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With