SQL Formatter & Beautifier
Format SQL online: put every major clause on its own line, uppercase the keywords, pick your comma style, and indent subqueries automatically. Or switch to Minify to squeeze a query onto one line. Free, no sign-up, runs entirely in your browser.
Formatting and minification run locally in JavaScript. Nothing is uploaded or logged.
Beautify places SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, INSERT, UPDATE, DELETE, SET and VALUES on their own lines, with subqueries indented inside parentheses.
What this SQL formatter does
This SQL formatter (or SQL beautifier) takes a query that arrived as one long line from an ORM log, a legacy stored procedure or a hastily pasted snippet, and rewrites it so the structure is obvious at a glance. Every major clause, including SELECT, FROM, WHERE, all JOIN variants, GROUP BY, ORDER BY, HAVING, LIMIT and UNION, starts on a new line, column lists break after each comma, and nested subqueries are indented one level deeper inside their parentheses. INSERT, UPDATE and DELETE statements get the same treatment, with SET assignments and VALUES rows split onto their own lines.
Three style options cover the conventions teams argue about most. Keyword case uppercases reserved words like SELECT and WHERE (or lowercases them, or leaves them as written) without touching your table and column names. Comma style switches between trailing commas and leading commas, the latter keeping diffs clean when you add a column. Indentation offers 2 spaces, 4 spaces or tabs. String literals, quoted identifiers and numbers pass through byte-for-byte, so the formatted query is semantically identical to the original.
Minify mode for embedding and logging
Switch to Minify and the tool collapses the query to a single compact line: comments are stripped and every run of whitespace becomes one space, while quoted strings stay exact. That is handy for embedding SQL in application code, passing queries through environment variables or config files, or fitting a statement into a single log line. The live size readout shows input bytes, output bytes and the percentage saved, so you can see exactly how much a verbose query shrinks.
How to format SQL online
Paste a query into the input box, click Load example to see a sample JOIN with aggregation, or upload a .sql file (read locally, never sent anywhere). Pick Beautify or Minify, adjust keyword case, comma style and indentation, and the output updates as you type. Copy the result or download it as a .sql file. The page is a single static script, so it handles large scripts without a server and keeps working offline after the first load.
Frequently asked questions
What does a SQL formatter do?
A SQL formatter (or SQL beautifier) takes a cramped or inconsistently written query and rewrites it so each major clause such as SELECT, FROM, WHERE, GROUP BY and ORDER BY starts on its own line with consistent indentation. The query logic, identifiers and string literals stay the same; only the layout of the source code changes.
Which SQL dialects are supported?
The formatter targets standard SQL, which covers the vast majority of queries written for MySQL, PostgreSQL, SQL Server, SQLite, MariaDB, BigQuery and similar engines. SELECT, INSERT, UPDATE and DELETE statements, all JOIN variants, subqueries, CTEs, CASE expressions, UNION, HAVING, LIMIT and window functions are all handled. Vendor-specific syntax is preserved as written even when it is not restructured.
What is the difference between trailing and leading commas?
Trailing commas sit at the end of each line (id, name,) while leading commas start the next line (, name). Leading commas make it easier to spot a missing comma and produce cleaner version-control diffs when you add or remove a column, because only one line changes. Neither style affects how the query runs.
Will formatting change how my query runs?
No. Databases ignore whitespace outside string literals, and this tool never alters identifiers, numbers or quoted strings. Keyword uppercasing only touches reserved words, not table or column names, so the formatted and minified queries are semantically identical to the original.
Is my SQL uploaded anywhere?
No. All formatting and minification runs locally in your browser with JavaScript. Your queries never leave your device, there is no server round-trip, and the page keeps working if you disconnect from the internet after it loads.