SELECT u . id, u . name, u . email, o . total_amount, o . created_at FROM users u INNER JOIN orders o ON u . id = o . user_id WHERE u . status = 'active' AND o . total_amount > 100 AND o . created_at >= '2025-01-01' GROUP BY u . id, u . name, u . email ORDER BY o . total_amount DESC LIMIT 50;
SQL readability directly affects code review quality, debugging speed, and the ability to catch logical errors before they reach production. A poorly formatted JOIN chain or a deeply nested subquery can hide a missing condition or an unintentional Cartesian product. SQL formatting tools apply the ANSI SQL standard keyword conventions — SELECT, FROM, WHERE, GROUP BY, ORDER BY — with consistent indentation so that the logical structure of a query is immediately visible, regardless of how the original was written.
The formatter tokenizes the SQL input into a stream of keywords, identifiers, operators, literals, and comments. SQL keywords defined in the ANSI SQL:2016 standard are recognized by a keyword list and normalized to the selected casing (UPPER, lower, or Title). The tokenizer handles edge cases including quoted identifiers (backticks, square brackets, double quotes), string literals with escaped quotes, and block comments.
The pretty-printer walks the token stream and applies indentation rules based on clause boundaries. SELECT columns are indented under SELECT. JOIN conditions are aligned under their JOIN keyword. Subqueries receive an additional indent level, and closing parentheses de-indent. CTEs (WITH clauses) are formatted as named blocks before the main query.
Minification runs the reverse: all whitespace tokens are collapsed to single spaces, newlines are removed, and consecutive whitespace inside string literals is preserved. The output is a single-line query suitable for embedding in application code or logging.
A data analyst reformats a 200-line report query generated by an ORM into readable SQL before submitting it to a DBA for performance review.
A backend developer minifies a parameterized SQL query before embedding it as a string constant in a Go source file, reducing visual clutter.
A developer pastes a hand-written query with inconsistent casing (select vs SELECT vs Select) and formats it to UPPER convention before adding it to a shared query library.
A database administrator formats an automatically generated migration script to verify the column types and constraints are correct before running it on production.
Paste your SQL query in the left panel
Choose keyword casing (UPPER, lower, Title) and indent size (2 or 4)
See the formatted output with syntax highlighting on the right
Copy the formatted SQL or download as a .sql file
We packaged the .claude config that runs this site — 26 specialist agents, 14 workflow skills, and 6 rule files from 31 real production incidents. From $9.
Get the Claude Code Production Pack — $29