Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the queries in SQL mostly written in Capital Letters?

Tags:

sql

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?

like image 812
saplingPro Avatar asked Feb 24 '12 05:02

saplingPro


People also ask

Do capital letters matter in SQL?

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.

Why do you think the keywords in SQL commands written are capitalized does it affect the query in anyway Why?

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.

Should SQL tables be capitalized?

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.

Is SQL capital sensitive?

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.


1 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.

like image 60
Justice Erolin Avatar answered Sep 19 '22 16:09

Justice Erolin