SQL Formatter

Formatly is a free, fast, 100% client-side SQL formatter that runs entirely in your browser. Paste a query to beautify and pretty-print SQL with consistent indentation and uppercase keywords, or minify it onto a single compact line — nothing is ever uploaded to a server.

Input
Output

SQL Formatter features

Format & Beautify

Pretty-print SQL with consistent indentation so SELECT, FROM, JOIN, and WHERE clauses line up cleanly.

Minify SQL

Collapse a query onto one compact line, stripping comments while preserving string literals exactly.

Uppercase Keywords

Automatically normalize keywords like select and from to SELECT and FROM for a uniform, readable style.

Choose Your Indent

Switch between 2 spaces, 4 spaces, or a tab to match your project or team conventions.

100% Private

Every query is formatted locally in your browser — nothing is ever uploaded or sent to a server.

Copy & Download

Copy the formatted SQL to your clipboard with one click, or download it straight to a file.

What is SQL?

SQL (Structured Query Language) is the standard language for querying and managing data in relational databases such as PostgreSQL, MySQL, SQL Server, Oracle, and SQLite. A typical statement combines clauses like SELECT, FROM, JOIN, WHERE, GROUP BY, and ORDER BY to describe exactly which rows and columns you want.

Because SQL ignores most extra whitespace, the same query can be written on one giant line or spread across dozens of neatly indented lines — and databases run both identically. That flexibility is great for machines but hard on humans: long, unformatted queries are difficult to read, review, and debug.

A SQL formatter (or beautifier) re-lays a query into a clean, consistent shape. Formatly's Format action uppercases keywords and applies uniform indentation so clauses, joins, and subqueries line up predictably. The Minify action does the opposite: it strips comments and collapses all whitespace onto a single compact line while leaving string literals and quoted identifiers byte-for-byte intact.

This tool is a pretty-printer, not a dialect-aware validator, so it does not run or check your query against a specific database engine — it focuses purely on readable, consistent layout. Use the Indent control to choose 2 spaces, 4 spaces, or a tab.

How to use the SQL Formatter

  1. Paste your SQL query into the editor, or load example data to try it out.
  2. Set the Indent control to 2 spaces, 4 spaces, or Tab to match your team's style.
  3. Click Format to pretty-print the query with consistent indentation and uppercase keywords.
  4. Or click Minify to strip comments and collapse the query onto a single compact line.
  5. Read the formatted result in the output pane, then click Copy to copy it or Download to save it as a file.
  6. Use Clear to reset both panes and start over with a new query.

SQL example: before & after

The messy single-line SELECT becomes a clean, multi-line query: keywords are uppercased, each clause sits on its own line, and the JOIN, WHERE, and ORDER BY conditions are indented so the structure is instantly readable.

Before

select id,name,email from users u join orders o on o.user_id=u.id where u.active=1 and o.total>100 order by o.created_at desc;

After

SELECT
  id,
  name,
  email
FROM
  users u
  JOIN orders o ON o.user_id = u.id
WHERE
  u.active = 1
  AND o.total > 100
ORDER BY
  o.created_at DESC;

Formatter vs beautifier vs validator vs minifier

Formatly offers two opposite SQL transformations, and the one you want depends on whether a human or a machine is reading the query next:

  • Format (beautify) expands a query for readability. It uppercases keywords and applies consistent indentation so clauses, joins, and subqueries are easy to scan, review in a pull request, or debug. Use it whenever you or a teammate need to read the SQL.
  • Minify compresses a query for compactness. It strips -- and /* */ comments and squeezes all whitespace onto a single line, while keeping string literals and quoted identifiers untouched. Use it when you want to store or embed the query — for example inside source code, a config value, or a log line.

Both actions leave the query's logic identical; only the layout changes. There is no validate step here because this tool is a pretty-printer, not a dialect-aware SQL checker.

Common SQL errors and how to fix them

  • Inconsistent keyword casing — mixing select, Where, and JOIN in the same query. Click Format. Formatly uppercases all keywords (SELECT, WHERE, JOIN) for a uniform, professional look.
  • No indentation on joins and subqueries, so the query structure is impossible to follow. Format the query to apply consistent, nested indentation that aligns each JOIN, ON, and nested SELECT.
  • A long single-line query that scrolls far off the right edge of the screen. Click Format to break the statement across multiple lines, putting each major clause on its own line.
  • Mixed tabs and spaces produce ragged, jumpy indentation across editors. Pick one option in the Indent control (2 spaces, 4 spaces, or Tab) and Format to apply it uniformly throughout.
  • Comments and extra whitespace bloat a query you want to embed in code. Click Minify to strip comments and collapse whitespace into one compact line, with string literals preserved.

Private by design

Every byte you paste into the SQL Formatter is processed locally in your browser. Formatly makes no network request with your data, logs nothing, and stores nothing on any server — so it is safe for API responses, tokens, configuration and other sensitive content. Your most recent input and theme are saved only in your own browser's local storage.

SQL Formatter FAQ

Is my SQL uploaded to a server?

No. The SQL formatter is 100% client-side — your query is formatted entirely in your browser using JavaScript. Nothing is ever sent to, stored on, or seen by a server, which makes it safe for queries that reference internal table names or sensitive schema.

Does this tool work offline?

Yes. Once the page has loaded in your browser, formatting and minifying run locally with no network requests, so you can keep using it even if your connection drops.

What is the difference between Format and Minify?

Format beautifies your query — it uppercases keywords and adds consistent indentation so the SQL is easy to read. Minify does the reverse: it strips comments and collapses everything onto a single compact line. Format is for humans; minify is for storing or embedding a query in code.

Does the formatter validate or run my SQL?

No. This is a pretty-printer, not a dialect-aware validator. It re-lays your query for readability but does not check it against a specific database engine or execute it, so it never connects to a database.

Will minifying change my data or break string literals?

No. Minify only removes comments and collapses whitespace between tokens. Text inside 'single quotes', "double quotes", and `backticks` — including doubled-quote escapes — is preserved byte-for-byte, so your literals stay exactly as written.

Can I choose tabs instead of spaces for indentation?

Yes. Use the Indent control to pick 2 spaces, 4 spaces, or a Tab, then click Format. The whole query is re-indented consistently with your chosen style.

Which SQL dialects does it support?

It formats standard SQL and handles common syntax used across engines like PostgreSQL, MySQL, SQL Server, and SQLite. Because it focuses on layout rather than dialect-specific validation, it works well for the everyday SELECT, INSERT, UPDATE, and JOIN statements you write day to day.