SQL Formatter
Format messy SQL into readable, indented queries with keyword highlighting.
About the SQL Formatter
Raw SQL queries pasted from logs, APIs, or other tools are often a single unreadable line. This formatter breaks SQL into structured, indented blocks — each main clause on its own line with consistent keyword capitalisation and colour highlighting.
What gets formatted
- Main clauses on new lines: SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY etc.
- All SQL keywords uppercased consistently
- Syntax highlighting: keywords in blue, strings in green, numbers in purple, conditions in amber
All processing is client-side — your queries never leave your browser.
Common SQL formatting conventions
Well-formatted SQL is easier to debug, review, and maintain. Most style guides recommend uppercase keywords (SELECT, FROM, WHERE), one clause per line, consistent indentation for subqueries, and comma-first or comma-last alignment for long column lists. Consistent formatting also helps version control diffs stay meaningful.
- Keyword casing — uppercase SQL keywords (SELECT, INSERT, WHERE) distinguish them visually from identifiers
- Line breaks — each major clause on its own line improves readability in long queries
- Indentation — indent subqueries and CTEs by 2-4 spaces relative to the parent query
- Aliases — always alias subqueries and use consistent alias conventions (e.g. first letter of table name)
Frequently Asked Questions
sql-formatter npm package: npx sql-formatter --language postgresql input.sql.