SQL Formatter
SQL Formatter beautifies or minifies SQL in one step. Beautify breaks a statement into indented clauses so you can read and review it; minify removes comments and collapses whitespace into a single line. Paste your query or load a text file from a URL, then copy the result or download it as a .sql file.
Use SQL Formatter
Output
Read Content
What this SQL formatter does
Paste a SQL statement and get it back either beautified — broken into clauses and indented so a human can read it — or minified into one compact line. The formatting runs on the server with the jdorn/sql-formatter library, and the result appears in a read-only editor where you can copy it or download it as a .sql file.
Nothing is executed. The tool never connects to a database, never validates that your statement would run, and never sends your schema anywhere except the formatter. It is a text transformation: in, formatted text out.
Beautify versus minify
Beautify
Beautify tokenises the statement, throws away the original whitespace, and rebuilds it with two-space indentation. Top-level clauses such as SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT and the JOIN family start on new lines; nested parentheses and subqueries gain an extra indent level; long column lists are split so each item sits on its own line. Inline constructs that read better on one line, such as short function calls, stay together.
Two things it deliberately does not do: it does not change keyword case, so select stays lowercase if that is how you wrote it, and it does not remove comments. Comments survive beautification, which is useful when you are cleaning up a migration or a query someone annotated inline.
Minify
Minify removes line comments and block comments, collapses every run of whitespace to a single space, normalises spaced-out reserved words such as OUTER JOIN, and trims the end. The result is one long line that is functionally the same statement, minus the comments. It is not an aggressive rewriter: it does not strip spaces around commas or operators, and it does not rename anything. If your goal is a tiny string to paste into an application config, this is the right mode; if your goal is byte-level golf, a dedicated SQL compressor will go further.
Using the page
- Choose Beautify or Minify with the two buttons at the top.
- Load a statement in one of two ways. The From URL tab fetches a text file over HTTP and drops its contents into the editor; the Manual tab gives you an editor with a Paste button.
- Check the language selector. It is set to SQL on this page, and the same widget also handles HTML, CSS, JavaScript, XML, JSON, PHP, YAML, INI, CSV, TOML and .env, so it is easy to knock it out of SQL by accident. If the output looks like nothing happened, confirm the selector still says SQL.
- Submit, wait for the round trip, then read the output panel.
- Use Copy for the clipboard or Download for a file named
beautify-output.sqlorminify-output.sql. - Character badges under the editor show input and output length, which is a quick way to see how much whitespace and comments were removed.
The URL tab is for fetching a plain text file, not for connecting to a database. It requests the address server-side and loads the response body into the editor, subject to the same character limit as pasted text.
The parenthesis and quote checker
As you type, the page adds coloured underlines in the input editor. Its checks are simple and local: it walks the text counting opening and closing parentheses, flags a closing parenthesis that has no match, warns when an opening one is never closed, and warns when the count of single or double quotes is odd. It stops after 50 annotations so a badly broken file does not flood the editor, and hovering a highlighted line shows the message.
Treat these as hints, not as a parser. The checker does not understand strings, comments or dialect-specific syntax, so a parenthesis inside a quoted string, a comment, or a Postgres dollar-quoted function body can produce a false warning. Conversely, balanced quotes do not prove the statement is valid. Its real value is catching a missing bracket in a long INSERT before you waste time debugging the database error.
Dialects and syntax the formatter may struggle with
The library recognises a broad set of standard and common keywords, but it is not a dialect-aware parser. MySQL backtick identifiers, SQL Server bracket identifiers, Postgres casts with double colons and dollar-quoted bodies, Oracle PL/SQL blocks and vendor-specific clauses are handled as generic tokens. Most of the time the output is still readable; in edge cases, a stored procedure body with internal semicolons can be reflowed in ways that look odd even though the text is preserved.
If you work with a dialect-heavy file, format a representative statement first and compare it against the original rather than applying the result blind. For a plain SELECT, INSERT, UPDATE, DELETE, CREATE TABLE or a join-heavy reporting query, beautify is usually clean.
When it is useful
- Code review. Turn a one-line query from a log into something a reviewer can scan clause by clause.
- Debugging. A missing comma or a misplaced WHERE is much easier to spot when each clause starts on its own line.
- Documentation. Paste a formatted statement into a runbook or a ticket without hand-indenting it.
- Storage. Minify a query before embedding it in a config file or an environment variable.
- Teaching. Show the structure of a complex join by breaking it apart.
Limits and behaviour
Input is capped at 200,000 characters per request. Anything larger is rejected by validation rather than truncated. The formatting call is a single request, so a very large script can take a moment to come back. The tool formats one blob of text at a time; it does not split a migration file into statements, does not execute them in order, and does not produce a diff against the original. If the library cannot tokenise part of the input, it keeps the text as-is rather than deleting it, which is why some unusual syntax survives unchanged.
Privacy
Unlike the browser-only tools on this site, this formatter is server-side: the SQL you paste is sent to the server to be formatted and returned in the response. Do not paste production credentials, connection strings, customer data or proprietary schema details you would not put in a request log. For a quick layout check, replace literals with placeholders before pasting. The page does not save your query into an account or a history, and the response is generated per request.
Common mistakes
- Leaving the language on something other than SQL. The widget is shared, so a stray click changes which formatter runs.
- Expecting uppercase keywords. The formatter preserves your casing; it does not normalise it.
- Assuming minify strips all whitespace. It collapses runs to one space and drops comments; it does not remove every space around punctuation.
- Trusting the quote warning on a procedure body. Dollar-quoted blocks and escaped quotes confuse a simple counter.
- Pasting secrets into a server-side tool. Use placeholders for anything sensitive.
- Treating success as validation. A formatted query is not a checked query.
Frequently Asked Questions
FAQ
Comments (0)
Describe the issue you encountered so we can investigate and improve the tool.