Overview

DDC Style Guide: SQL

ORM-oriented SQL conventions for Java projects.

In Structured Query Language (SQL) programming, there really isn’t an equivalent to GJSG, or even to the earlier, more basic Code Conventions for the Java™ Programming Language (last updated by Sun in 1999, and currently made available only for archival purposes by Oracle). Most of the guidelines included in both of those publications are followed by the overwhelming majority of Java developers; however, there isn’t a SQL style guide with anything close to the same rate of formal adoption or informal conformance.

In this style guide, the focus is primarily on naming (including casing), and on a few general formatting rules. Most of these are long-established, and widely followed—though with plenty of variation from organization to organization. One benefit of this flexibility is that many SQL formatters can be configured to apply several of these rules; this includes the Code/Reformat code feature of IntelliJ, which—when using the default settings—will apply most of the formatting rules (but not the structural or naming & letter-casing rules) given here.

This style guide is deliberately oriented toward using SQL via an object-relational mapping (ORM) library. That is, it’s generally assumed that an ORM such as Hibernate or Room will be be managing persistence, and—in most cases for this bootcamp—generating the SQL DDL code to implement the data model in a database schema. Thus, there is not much attention placed on formatting details for SQL statements; instead, naming and letter casing of keywords and identifiers are the main focus, with a secondary focus on formatting (primarily for the purpose of producing technical documentation).

Some of the rules here are based on Simon Holywell’s SQL Style Guide (SSG). However, where the DDC Java style rules incorporate those in GJSG with only a few amendments, the DDC SQL style guide deviates significantly from SSG. Thus, the rules below should be treated as normative, in preference to contradicting rules in the SSG.

On the other hand, beyond newline and indentation rules, this style guide doesn’t address any other specifics of vertical alignment—a topic of great disagreement in SQL code formatting. SSG or other SQL style guides may be consulted for this purpose.

Section contents