This guide is an outline of the coding style to be used in dbs211, dbs311, dbs610, and dbs710 courses. Please speak with your professor regarding this requirement if it was not made clear.
The following is a standard SQL style guide that will allow SQL to be consistent, easy to read, and comply with industry standards. This guide was developed from the base Mozilla online standards found at: SQL Style Guide - Mozilla Data Documentation and are therefore a good standard for students to follow and be ready for a variety of style guides found with their future work places.
SELECT
field_name1 AS alias1,
field_name2,
field_name3
FROM tablename
WHERE
field_name2 > somevalue
ORDER BY field_name2 DESC;
SELECT
table1.field_name1 AS alias1,
table1.field_name2,
table2.field_name3
FROM
table1 t1 INNER JOIN table2 t2 ON t1.field_name1 = t2.field_name3
INNER JOIN table3 t3 ON t2.field_name3 = t3.field_name4
WHERE
table1.field_name2 > somevalue
ORDER BY table1.field_name2 DESC;
If the content of parentheses span multiple lines, then:
CREATE VIEW view_name AS (
SELECT *
FROM table_name
);
Boolean operators should always be placed at the beginning of a new line:
SELECT
fieldlist
FROM table_name
WHERE
condition1
AND condition2
OR condition3
ORDER BY fieldname;