Code Style Guide: SQL

unruthless edited this page Sep 13, 2010 · 5 revisions
Clone this wiki locally

This is the Code Style guide for SQL. See the main Code Style Guide page for other languages.

SQL statements should have SQL keywords in ALL CAPS.

Correct:
SELECT * FROM table;

Incorrect:
select * from table;

Never use backticks.

If you find that backticks are needed, that indicates that there is a design problem somewhere. Rather than use backticks, try to fix the design problem.

When specifying an alias for a column or table name, always use the AS keyword.

Correct:
SELECT n.name AS myname FROM names AS n;

Incorrect:
SELECT n.name myname FROM names n;