Skip to content
Private: files never leave your device

SQL Formatter

SQL formatter that turns a one-line query into readable SQL with uppercase keywords, one clause per line and indented joins and conditions. Free and private.

SQL Formatter tool

Formatting a SQL query, step by step

  1. Paste your query into the box, or press Load sample to try an example.
  2. Choose the indent: 2 spaces, 4 spaces or tabs.
  3. Press Beautify. Every clause moves to its own line and keywords become uppercase.
  4. Copy the output or save it as a .sql file.

How the layout changes

Queries pulled from an ORM log or a monitoring dashboard tend to arrive as one endless line. The formatter breaks them at the clauses your eye looks for: SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, INSERT, UPDATE and SET. Each join begins a new line with its full type kept together (LEFT OUTER JOIN stays as one piece), while ON, AND and OR are indented under the clause they belong to. A range like BETWEEN 10 AND 100 stays on a single line, since that AND is part of the range rather than a new condition.

SELECT u.name, COUNT(o.id) AS orders
FROM users u
INNER JOIN orders o
  ON u.id = o.user_id
WHERE o.total > 100
  AND u.active = 1
GROUP BY u.name
ORDER BY orders DESC

What is never altered

Text inside single quotes, double quotes or backticks is lifted out before formatting and restored afterwards, so a value like 'O''Brien -- VIP' keeps its exact spacing and is never treated as a comment. Comments get the same protection, and a -- comment is always followed by a line break so it cannot swallow the code after it. Only whitespace and keyword case change, so the formatted query returns exactly the same rows.

Minifying for config and code

Minify does the reverse: it strips comments and squeezes the query onto one line. That helps when a query has to sit inside a JSON config, an environment variable or a string in your application.

Have several statements? End each one with a semicolon. They are formatted separately with a blank line in between.

SQL Formatter at a glance

SQL formatter: lay out SQL queries with uppercase keywords and tidy indentation, or minify them. Works for MySQL, PostgreSQL and SQLite. Private.

Cost
Free to use, with no account, watermark or usage cap.
Privacy
Processing happens on your device; nothing is sent to our servers.
Devices
Up-to-date Chrome, Edge, Firefox or Safari on computers, Android phones and iPhones.
Last updated

Frequently asked questions

Which SQL dialects does it handle?

MySQL, PostgreSQL, SQLite and standard ANSI SQL, including joins, subqueries and nested brackets.

Could formatting change what my query does?

No. Only whitespace and keyword case change, so the query returns exactly the same results.

Is my SQL uploaded?

No. It all runs in your browser, so sensitive queries stay on your device.