QueryTidy
Turn long SQL statements into something readable, with clause highlighting.
Input SQL
Formatted SQL
How SQL formatting works
QueryTidy tokenizes the query respecting strings and comments, and places each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY...) on its own line, indenting AND/OR conditions and column lists so the structure is obvious at a glance:
-- Before select id, name, email from users where active = 1 and role = 'admin' order by name asc -- After SELECT id, name, email FROM users WHERE active = 1 AND role = 'admin' ORDER BY name asc
The tokenizer and indentation rules run entirely in your browser with native JavaScript — no external libraries, no server calls.
Frequently asked questions
What SQL dialects does it support?
Formatting is based on standard keywords (SELECT, FROM, WHERE, JOIN, GROUP BY...) common to MySQL, PostgreSQL, SQLite and SQL Server. It doesn't validate engine-specific syntax, only reorders and highlights.
Is it based on a full SQL parser?
No. It uses heuristic rules by keyword and parenthesis depth, similar to most online SQL formatters. For very complex, deeply nested queries the result may need manual tweaks.
Does it respect text inside strings and comments?
Yes, the tokenizer recognizes single/double-quoted literals and -- or /* */ comments as atomic blocks that don't get split or recolored as keywords.
Is it safe to paste queries with sensitive data?
Yes. All formatting happens in your browser; no query is ever sent to a server.