SQL Formatter
Free online SQL formatter and SQL beautifier that turns compact or messy queries into clean, readable SQL. Major clauses get their own lines, column lists are indented, and keywords can be uppercased with one click. Switch to SQL minifier mode for storing queries as strings. Works with SELECT, INSERT, UPDATE, DELETE, JOINs, CTEs and subqueries. No signup, runs entirely in your browser.
Paste Your SQL
Any query, any dialectCtrl+Enter (or Cmd+Enter) inside the textarea to beautify instantly. String literals, quoted identifiers and comments are never touched, so your data stays exactly as you wrote it.
Output
Ready when you areYour formatted or minified SQL will appear here
Paste a query and click Beautify SQL or Minify SQL.
What does this SQL Formatter do?
This free online SQL formatter — also called a SQL beautifier or SQL pretty printer — takes compact, poorly indented or copy-pasted SQL and rewrites it with consistent indentation, spacing and line breaks so it is readable and editable. Major clauses like SELECT, FROM and WHERE get their own lines, column lists are indented, and joins and subqueries are aligned so the structure of the query is obvious at a glance.
The same tool works in reverse. Switch to SQL minifier mode and it collapses your query into the most compact safe form, removing extra whitespace and comments. That is exactly what you want when you're storing queries as strings inside application code, config files or test fixtures.
Everything runs locally in your browser. The SQL you paste never leaves your device, there is no signup, and there are no usage limits. Format or minify as many queries as you want, as many times as you want, for personal or professional projects.
How to format and beautify SQL queries
- Paste your SQL into the input box on the left. Any query works — hand-written, copied from a logs viewer, or auto-generated by an ORM.
- Choose your options. Pick the indentation size (2 spaces, 4 spaces or tab), whether to uppercase SQL keywords, and whether to keep comments.
- Click Beautify SQL. The formatter rewrites the query with clause breaks and consistent indentation. The output appears instantly on the right.
- Or click Minify SQL for compact form. The stats panel shows how many bytes you saved.
- Copy or download. Use Copy Output to grab the result, or Download .sql to save it as a file.
Why use this SQL Formatter?
Instant formatting
The formatter runs entirely in your browser, so the output appears the moment you click. No server round-trip, no waiting.
Configurable style
Choose 2-space, 4-space or tab indentation. Toggle uppercase keywords and comment preservation on or off.
Beautify + minify
One tool does both: expand compact SQL for reading, or compress readable SQL for storing. The stats panel shows exactly how many bytes you saved.
Dialect-agnostic
Handles standard SQL used by PostgreSQL, MySQL, SQLite, SQL Server and Oracle: SELECT, INSERT, UPDATE, DELETE, JOINs, CTEs and subqueries.
100% private
Everything runs locally. The SQL you paste never leaves your device — no server, no logs, no tracking.
Works offline
Once the page loads, you can format or minify SQL without an internet connection. Bookmark it for offline work.
What exactly gets changed?
Here is a complete list of what the formatter handles and how, so you know exactly what to expect.
| Element | Beautify | Minify |
|---|---|---|
| Major clauses (SELECT, FROM, WHERE, GROUP BY…) | Each on its own line at base indent | Kept inline with single spaces |
| Column lists (after SELECT, GROUP BY, ORDER BY) | One column per line, indented | Kept on one line, comma-separated |
| JOIN clauses | Each on its own line at base indent | Kept inline |
| ON / USING conditions | Indented under the JOIN | Kept inline |
| AND / OR in WHERE | Each on its own line, indented | Kept inline |
| Keywords | Uppercased (toggleable) | Uppercased (toggleable) |
String literals ('...') | Preserved exactly | Preserved exactly |
Quoted identifiers ("...", `...`, [...]) | Preserved exactly | Preserved exactly |
Line comments (--) | Preserved (toggleable) | Removed |
Block comments (/* */) | Preserved (toggleable) | Removed |
| Numbers & operators | Untouched | Untouched |
| Query semantics | Identical | Identical |
Who uses an SQL formatter?
Anyone who reads, writes or reviews SQL benefits from formatting. Here are the most common use cases:
Back-end and full-stack developers
- Format auto-generated queries from ORMs before debugging them
- Standardise indentation across a codebase where different teammates have different styles
- Minify queries before storing them as strings in source code
- Format pasted queries from logs, error reports or bug trackers
Data analysts and BI engineers
- Format long analytical queries before running them in a notebook
- Make CTEs and window functions readable so reviewers can follow the logic
- Format queries from other analysts to understand their approach
DBAs and database engineers
- Format stored procedures and views for code review
- Compare two versions of a query side by side after formatting
- Standardise migration scripts before committing them
Students and learners
- Format textbook examples to see the structure clearly
- Learn how major clauses nest and how JOINs relate to their tables
- Practice writing consistent, professional-looking SQL
SQL beautify vs. SQL minify — what is the difference?
These two operations are opposites, and this tool does both.
| Mode | What it does | Best for | Typical size change |
|---|---|---|---|
| Beautify / Format | Adds indentation, line breaks and clause breaks. Expands compact SQL into a readable structure. | Development, debugging, code review, learning | Increases size (adds whitespace) |
| Minify | Removes whitespace and comments. Collapses the query into the smallest safe form. | Storing queries in source code, config files, test fixtures | 20–50% smaller |
If you have readable SQL and need to compact it — for example to embed in a JavaScript string or a YAML config — use Minify SQL. If you have a wall of SQL and need to understand it, use Beautify SQL.
SQL formatting best practices
Whatever style you choose, keep it consistent across your team. Here are the conventions most teams follow:
- Uppercase SQL keywords. Makes keywords stand out against identifiers and strings.
- One clause per line. SELECT, FROM, WHERE, GROUP BY etc. each start on their own line.
- One column per line. A long SELECT list is easier to scan vertically than horizontally.
- Indent subqueries and CTEs. Nesting should be visible at a glance — the deeper you go, the more indent.
- Lead with
AND/OR. In a WHERE clause, put the operator at the start of the line so a reviewer can count conditions easily. - Group JOINs under FROM. Every JOIN at the same indent level as FROM, with its ON condition indented below.
- Align column aliases. Optional but makes wide SELECT lists more readable (
u.id AS user_id). - Use comments for intent, not mechanics. Explain why a filter is there, not what the syntax does.
- Keep lines under ~100 characters. Wrap long expressions with parentheses and indentation.
- Run the formatter before committing. A consistent diff is easier to review than one that mixes styles.