Why Should I Capitalize My SQL Keywords

Why should I capitalize my SQL keywords? Is there a good reason?

I think the latter is more readable. You can easily separate the keywords from table and column names, etc.

Is there a good reason to use upper case for SQL keywords?

It's just a matter of style, probably originating in the days when editors didn't do code colouring.

I used to prefer all upper case, but I'm now leaning towards all lower.

Either way, be consistent.

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

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.

Why are SQL entries written in uppercase?

SQL was developed in the 1970s when the popular programming languages (like COBOL) used ALL CAPS, and the convention must have stuck.

Should I use the commands My Sql in capital letters?

It is not required to use capital letters. You could use small letters too.

However for structure of code, to beautify the code and to show highlights it is better to use Capital letters in syntax such as INSERT instead of insert. This will help to identify easily when we write complicated scripts with subqueries.

And as per human nature, Capital letters are fast visible than small letters.

Hope this helps.

Why are MySQL queries almost always written in Capital

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.

Is SQL syntax case sensitive?

The SQL keywords are case insensitive (SELECT, FROM, WHERE, etc), but they are often written in all caps. However, in some setups, table and column names are case sensitive.

MySQL has a configuration option to enable/disable it. Usually case sensitive table and column names are the default on Linux MySQL and case insensitive used to be the default on Windows, but now the installer asked about this during setup. For SQL Server it is a function of the database's collation setting.

Here is the MySQL page about name case-sensitivity

Here is the article in MSDN about collations for SQL Server

Should I write table and column names ALWAYS lower case?

It is not a technical problem for the database to have uppercase letters in your table or column names, for any DB engine that I'm aware of. Keep in mind many DB implementations use case sensitive names, so always refer to tables and columns using the same case with which they were created (I am speaking very generally since you didn't specify a particular implementation).

For MySQL, here is some interesting information about how it handles identifier case. There are some options you can set to determine how they are stored internally. http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html



Related Topics



Leave a reply



Submit