๐๏ธ SQL Formatter
Paste a messy SQL query to reformat it into a readable, indented layout โ keywords like SELECT, FROM, WHERE, and JOIN are uppercased and each major clause starts on its own line. Switch to Minify mode to collapse a query into a single compact line. This is a best-effort formatter based on pattern matching, not a full SQL parser, so it works best on standard SELECT/INSERT/UPDATE/DELETE statements.
How to use
- Paste the SQL query you want to format or minify into the input box.
- Click "Format" or "Minify."
- See the formatted or minified query in the output box.
- Click "Copy" to copy the result to your clipboard.
How the calculation works
This is not a full SQL parser. It finds text matching keyword patterns and inserts line breaks and indentation. Major clauses such as SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY are uppercased and placed at the start of a line, with SELECT columns and JOIN ON conditions indented beneath. Some keywords span several words, such as "INSERT INTO" and "ORDER BY", so keywords are matched longest first. That stops a short keyword like "IN" from matching first and wrongly splitting "INSERT". Minify mode strips line breaks and extra whitespace to put the query on one line โ handy for logging or embedding in a string in code.
Worked example
Formatting this one-line query select id, name from users u join orders o on u.id = o.user_id where o.total > 100 order by o.total desc gives SELECT id, name FROM users u JOIN orders o ON u.id = o.user_id WHERE o.total > 100 ORDER BY o.total desc Clause keywords are uppercased; words outside the clause keyword list, such as desc, are left as typed.
Things to be aware of
- This is not a full SQL parser. Deeply nested subqueries and vendor-specific syntax may format poorly.
- If a string literal contains a word identical to a keyword, a line break may be inserted there.
- Formatting does not change what the query does, but still review it before running it.
- Your SQL is processed in the browser and never sent anywhere.
FAQ
Does it support every SQL dialect?
It handles common ANSI SQL syntax (SELECT, JOIN, WHERE, GROUP BY, etc.) reasonably well, but it is not a full parser, so highly vendor-specific syntax may not format perfectly.
Is my SQL sent to a server?
No. Formatting happens entirely in your browser โ nothing is uploaded or stored.
Can it clean up a long single-line query?
Yes โ paste a long, unbroken query copied from a tool or log, and formatting breaks it into a readable, clause-by-clause layout.
Does it handle INSERT and UPDATE statements?
Yes โ it's designed to work best on standard SELECT, INSERT, UPDATE, and DELETE statements.
Will it correctly format complex SQL with subqueries?
Since it relies on pattern matching rather than a full parser, deeply nested subqueries or unusual syntax may not format exactly as expected โ check the result before relying on it.