Establish a team SQL style guide
The most important formatting decision is consistency. Pick UPPERCASE or lowercase keywords, pick 2-space or 4-space indentation, and document it. All team members should produce SQL that looks the same structurally. The formatter enforces your chosen convention mechanically, removing the need to debate formatting in code review and making query diffs meaningful rather than noise-filled.
Format before committing to version control
SQL queries stored in version-controlled files (migration files, stored procedure definitions, ORM query files) should always be formatted before committing. Unformatted or inconsistently formatted SQL creates noisy diffs when re-formatted later, burying actual logic changes in whitespace changes. Format once before the first commit and maintain the formatting thereafter.
Use formatting to spot logical errors
Many SQL bugs become visible only when the query is properly formatted. A WHERE clause with OR conditions that should be grouped with parentheses but are not, a JOIN ON condition that references the wrong table, a subquery that is more complex than it needs to be — these issues are much harder to see in a single-line query. Formatting is a debugging tool as much as a readability tool.
Format generated SQL for debugging
ORMs (Hibernate, SQLAlchemy, ActiveRecord, Prisma) generate SQL that is often logged as a single compressed line. When debugging a query performance issue or incorrect result, paste the ORM-generated SQL into the formatter to make it readable, then analyse the JOIN order, WHERE conditions, and subqueries. This is one of the most common real-world uses of a SQL formatter.
The 4-space indent standard
Four spaces is the most readable indentation for SQL because SQL clauses are short keywords (FROM, WHERE, JOIN) — 2-space indentation makes sub-conditions look like they are at the same level as the clause keyword. Four spaces creates enough visual separation to distinguish clause headers from their contents clearly. Use 2 spaces only if your team already has a strong 2-space convention from other languages.