SQL Formatter
Format SQL with clause-aware indentation and consistent keyword casing.
Paste a query to format it.
Features
- Clause-aware line breaks and indentation
- Configurable keyword casing
- Leading or trailing comma style
- Compact mode for single-line output
- Query summary listing tables and clauses
How to use it
- Paste your SQL into the input box.
- Choose keyword casing and indentation.
- Press Format.
- Copy the result into your editor or migration file.
Formatting conventions and why they matter
Uppercase keywords are the long-standing convention, and the reason is practical rather than aesthetic: SQL has no visual distinction between keywords and identifiers, so uppercasing SELECT, FROM and WHERE lets you find the structure of a long query at a glance. Table and column names stay lowercase, which makes the two categories immediately distinguishable without syntax highlighting.
Leading commas look strange at first but solve a real problem. When each line begins with a comma, commenting out a column means deleting or commenting one line without touching its neighbours. With trailing commas, removing the last column in a list leaves a dangling comma that breaks the query, a small annoyance that happens constantly while debugging.
The formatting choice that matters most for reviewability is putting each JOIN and each condition on its own line. A five-table join written on one line is unreadable and hides mistakes; the same join with one table per line makes a missing ON clause or an accidental cross join immediately visible. This formatter breaks on the major clause keywords and indents JOIN conditions under their join, which is the convention most style guides converge on.
Frequently asked questions
Related tools
Further reading
Read the full guide on the 123MiniApps blog.