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 dialect
Pro tip: Press Ctrl+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 are

Your 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

  1. 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.
  2. Choose your options. Pick the indentation size (2 spaces, 4 spaces or tab), whether to uppercase SQL keywords, and whether to keep comments.
  3. Click Beautify SQL. The formatter rewrites the query with clause breaks and consistent indentation. The output appears instantly on the right.
  4. Or click Minify SQL for compact form. The stats panel shows how many bytes you saved.
  5. 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.

ElementBeautifyMinify
Major clauses (SELECT, FROM, WHERE, GROUP BY…)Each on its own line at base indentKept inline with single spaces
Column lists (after SELECT, GROUP BY, ORDER BY)One column per line, indentedKept on one line, comma-separated
JOIN clausesEach on its own line at base indentKept inline
ON / USING conditionsIndented under the JOINKept inline
AND / OR in WHEREEach on its own line, indentedKept inline
KeywordsUppercased (toggleable)Uppercased (toggleable)
String literals ('...')Preserved exactlyPreserved exactly
Quoted identifiers ("...", `...`, [...])Preserved exactlyPreserved exactly
Line comments (--)Preserved (toggleable)Removed
Block comments (/* */)Preserved (toggleable)Removed
Numbers & operatorsUntouchedUntouched
Query semanticsIdenticalIdentical

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.

ModeWhat it doesBest forTypical size change
Beautify / FormatAdds indentation, line breaks and clause breaks. Expands compact SQL into a readable structure.Development, debugging, code review, learningIncreases size (adds whitespace)
MinifyRemoves whitespace and comments. Collapses the query into the smallest safe form.Storing queries in source code, config files, test fixtures20–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.

Frequently asked questions

An SQL formatter (also called a SQL beautifier or SQL pretty printer) takes messy or compact SQL and rewrites it with consistent indentation, spacing and line breaks so it is readable and editable. Major clauses like SELECT, FROM and WHERE are placed on their own lines, and column lists are indented for clarity.
Yes, completely free. No signup, no watermark, no hidden charges. Format or minify as much SQL as you want, for personal or commercial projects.
No. Formatting only changes whitespace and line breaks. Keywords, identifiers, string literals and values stay exactly the same. The query behaves identically when run against your database.
The formatter is dialect-agnostic for common SQL: SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER TABLE, JOINs, subqueries, CTEs (WITH), CASE expressions, and standard functions. Specialized dialect-specific syntax (PostgreSQL-specific types, MySQL-specific extensions, T-SQL features) will format reasonably but may not be perfectly aligned.
Yes. Both line comments (--) and block comments (/* */) are preserved by default. You can toggle comment preservation off for a cleaner output.
Yes. Toggle the uppercase keywords option and every SQL keyword (SELECT, FROM, WHERE, JOIN, etc.) gets converted to uppercase. String literals, quoted identifiers and comments are never touched.
Absolutely. Everything runs in your browser. The SQL you paste never leaves your device — no server processing, no logging, no data storage.
Yes. Once the page loads, the SQL formatter works without an internet connection. Bookmark it for offline work.
Yes. The tool is fully responsive and works on phones, tablets and desktops. The input and output panels stack vertically on small screens.
Beautify expands SQL with indentation and line breaks for readability — perfect for development, debugging and code review. Minify compresses SQL by removing whitespace and comments for smaller size — useful for storing queries as strings in source code.