tags:

views:

85

answers:

4

Possible Duplicate:
Why should I capitalize my SQL keywords?

hi,

I'm pretty new to SQL, but i've noticed that writing

SELECT * FROM column_name

is almost always used when

select * from column_name

yields exactly the same result. I can't find anything online about this. Is this just a convention? Or will not using uppercase break the script on older systems/systems that i'm not aware of?

thanks

+2  A: 

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

dan04
+1  A: 

They are completely equivalent, the uppercase just makes the query easier to read.

Andy
+1  A: 

It's because that is the way it is defined in the ANSI standard. See section 5 Lexical elements, I presume it caught on from there.

http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

Chris Diver
+1  A: 

Notice this is really depending on your sql database implementation. Oracle tends to convert everything to uppercase. Postgresql on the contrary, will convert sql keywords or column identifier to lowercase. For idendifiers (tables, columns, ...) you can prevent your database from being "clever" by double-quoting them.

select "TeST" from MyTable;

will be translated in Oracle to SELECT "TeST" FROM MYTABLE; and in Postgresql to select "TeST" from mytable;

Also consider this behaviour when using jdbc for example, as the column names retrieved in the ResultSet will also follow these rules, so double-quoting identifiers might be a good practice if you consider portability.

alci