Last updated ·Published ·By the WiserWork team
SQL Formatter
Beautify SQL queries with proper indentation & keyword highlighting
Paste a query that arrived as one enormous line and this formatter breaks it at every clause boundary, indents the body two spaces and uppercases the SQL keywords it knows.
What is the SQL Formatter?
The SQL Formatter is a text-level beautifier for queries. It collapses the whitespace in whatever you paste, inserts a line break in front of 19 clause keywords such as SELECT, FROM, WHERE, the JOIN variants, ON, AND, OR, GROUP BY, ORDER BY, HAVING, LIMIT and UNION, indents everything below the opening statement verb by two spaces, then uppercases the 43 keywords in its list. It is not a parser and it does not check syntax: a query with a missing comma or a misspelled table name is laid out just as cheerfully as a correct one.
Key Features
- Splits the query at 19 clause keywords, one clause per line
- Uppercases 43 keywords, including COUNT, DISTINCT, BETWEEN and LIKE
- Indents clause lines two spaces beneath the opening statement verb
- Reformats on every keystroke; the Beautify button simply re-runs it
- Nothing is executed or uploaded, and no database is ever contacted
Common Use Cases
- Unfolding a one-line query copied out of an application log or ORM trace
- Making a query readable before pasting it into a pull request for review
- Normalizing keyword casing so a diff shows real changes, not styling churn
- Reading an inherited report query with six joins and a stack of conditions
How to Use the SQL Formatter
- Replace the sample SELECT in the left pane with your own query.
- Watch the right pane rebuild as you type; that output box is read-only.
- Press Beautify to force a re-run after pasting with the mouse.
- Hit Copy to put the formatted query on your clipboard.
- Use Swap to send the result back to the left pane and format it again.
Tips for Best Results
- Keywords inside quoted strings are still treated as keywords, so a value like 'order by date' gets split.
- Double-dash comments are risky: the query is flattened first, so following text can end up commented out.
- Columns named count, min or max are uppercased too, because matching is purely by whole word.
- CTEs, subqueries and window functions are not indented as nested blocks; only top-level clauses move.
Why Use WiserWork's SQL Formatter?
Formatted SQL matters most where queries are read rather than run: in pull requests, in migration files, in the query someone pastes into an incident channel at two in the morning. When every clause starts on its own line, a diff points at the condition that actually changed instead of a whole reflowed paragraph, and a reviewer can see the join order at a glance. This tool gives you that layout in one pass without connecting to anything.
Who Uses the SQL Formatter?
Backend and data engineers reach for it when a query arrives folded into a single line by a logger or an ORM. Analysts paste in report SQL inherited from someone who has since left. Reviewers run it before commenting on a pull request so that everyone is arguing about the same shape of query.
Frequently Asked Questions
Does it check my SQL for errors?
No. It is a text formatter, not a parser, so a query with a missing comma or an unbalanced parenthesis is reformatted exactly as happily as a valid one. Only your database can tell you whether the query runs.
Which SQL dialects does it handle?
The keyword list is generic ANSI-style SQL plus LIMIT and OFFSET, which suits MySQL, PostgreSQL and SQLite well. Dialect-specific words such as TOP, MERGE, RETURNING, OVER and PARTITION BY are not in the list, so they are neither uppercased nor given a line of their own.
Can I choose lowercase keywords or a wider indent?
No, both are fixed. Every keyword it recognizes comes out uppercase, and the indent is always two spaces with no setting to change it. If your team standard differs, run the output through your editor afterwards.
What happens to comments in my query?
The formatter collapses everything onto one line before splitting it, so a double-dash line comment can swallow whatever followed it unless a clause keyword happens to come next. Block comments usually survive, but check them in the output.
Why did it break a line in the middle of my text string?
Because matching happens on raw characters, with no idea where a string literal starts. If a quoted value contains a word like ON, AND or ORDER BY, that word is treated as a clause and gets a line break in front of it. Review quoted values after formatting.
Does it handle CTEs and subqueries?
It formats the keywords inside them but does not indent them as nested blocks. WITH is not in its keyword list, so a CTE header stays on the line where it began and the subquery body is flattened out to the top level.
Is my query sent anywhere?
No. The formatter is JavaScript in the page, with no server round trip, no database connection and no storage. Load the page, disconnect from the network, and it keeps working.
What does the Swap button do?
It moves the formatted output back into the input pane and re-runs the formatter. Because the output is already normalized, a second pass produces identical text, so Swap is a safe way to keep working from the version you like.
Can it format several statements at once?
Yes. Semicolons are left alone and each INSERT, UPDATE or DELETE starts fresh at the left margin. There is no blank line inserted between statements, so a long script still runs together visually.
Is there a length limit?
No cap is set in the code. Formatting is a series of regular expression passes over one string, so a few thousand lines is comfortable on a desktop, while a huge generated query may freeze the tab for a moment.
A formatter cannot tell you whether a query is correct, but it can stop the shape of the text from hiding the answer. Paste the query, read the clauses down the left edge, and get back to the actual problem.