QueryTidy
Turn long SQL statements into something readable, with clause highlighting.
Input SQL
Formatted SQL
What is QueryTidy?
QueryTidy is a SQL formatter: it takes a database query written as one long, hard-to-read line and rewrites it with each clause (SELECT, FROM, WHERE, JOIN...) on its own line and consistent indentation, so you — or whoever reviews your code — can actually follow its structure. SQL is the language used to ask a database for data; this tool doesn't run the query, it just makes the text easier to read.
How to use QueryTidy
- Paste your SQL into the Input SQL panel, or click Example to try a sample query.
- Choose 2 or 4 spaces of indentation, and toggle Uppercase to control whether keywords like SELECT/WHERE are capitalized.
- Read the formatted, clause-by-clause result in the Formatted SQL panel on the right.
- Click Copy to copy it, or Download to save it as a file.
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.