Do SQL clauses always have to be entirely capitalized?

Question

When writing SQL queries, do the commands, like SELECT and FROM have to be all capital letters?

Answer

No, SQLite, which Codecademy uses, is case-insensitive when it comes to clauses like SELECT and FROM which can be cased in any way. This is different from other programming languages such as Python where casing is quite important.

Example

/* Both of the following queries will return the same result. */
SELECT * FROM table;

select * from table;
15 Likes

Is capitalizing the common practice though?
Why do codecademy exercises have the commands capitalized?
Also, how about data types such as INTEGER, REAL, DATE, etc

55 Likes

For those who liked my question (I assume u guys are interested in the answer)

after looking here and there, including stack-overflow: it does not matter

capitalization is suggested for better reading but not necessary especially with the IDEs that people work with today, in which the keywords are automatically highlighted in different color

Pretty much, it depends on who you are working with and what standards you guys plan to set;
on your own, feel free to do whatsoever (capitalize it or not) ;o

99 Likes

In my previous job we capitilized just to make it easier to read.

14 Likes

I heard that Oracle DB automatically uppercases all commands, whereas PostgreSQL lowercases all of them. However, I never understood the point of that - if both are actually case-insensitive…?

3 Likes

I also thinks it help to make the command more readable in my opinion :wink:

2 Likes

It’s looks more easily readable and decent if capitalised though its cosmetic.

1 Like

Was wondering this from minute 1!

2 Likes

Running SQLite3 through the Linux CLI Shell, I can get every clause to work fine no matter whether I capitalize or not. However, to query the DB and successfully print the results to the screen, I must capitalize
SELECT * FROM db;
Interesting, I wonder why.

4 Likes

why

SELECT name, genre, year FROM movies;

is not working (one unique row)?

It works fine for me. I assume you didn’t exactly follow the 1st task.

Thank you for clarifying the answer to the above questions- I was wondering about capitalization myself - so this is good to know.

Why we will captilize the Commands maximum time in Sql why don’t we use the small letters frequently in sql?

Did you remove what you entered in the first question?
Clear it and it will work.

1 Like

This is up to personal preference whether you choose to use purely capitalization or no, but back in the days, when we didn’t have these fancy IDEs with the keywords having colors to give more readability, the only way to add readability back then was just using capitalization

1 Like

i am using MySQL too and you can write your command in lowercase because they will have a different color on screen

I work in a large team and we use SQL Server and have 1000s of .sql files with 1000s of lines SQL in Azure DevOps. We all agreed to use lower case for typing speed reasons if anything. With all the syntax highlighting, our files are just as easy to read as if the commands were upper case. Most of us, including me, are dyslexic and we do just fine with lower case :smiley: