SQL Formatter and Beautifier

Beautify messy or one-line SQL with proper indentation, or minify it back to a single line. Supports MySQL, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake and more. Runs in your browser.

Why format SQL?

Formatted SQL is dramatically easier to read, debug and review. A long single-line SELECT with several joins is impenetrable; the same query with each clause on its own line, properly indented, makes the data flow obvious. That matters in code review, in bug reports, and when you are reading an ORM’s debug log at 2 a.m.

Three styles: indented, clause per line, minified

StyleWhat it doesUse it for
IndentedParses the query for the chosen dialect and lays it out fully: one select column per line, JOIN … ON and subqueries indented, keyword case applied.Code you will commit, review or document.
Clause per lineA light SQL beautifier: collapses whitespace and starts each major clause on a new line. Nothing else changes, and it never fails on unusual syntax.A quick look at a run-on query from a log, or SQL the parser does not understand (templating, vendor extensions).
MinifyRemoves -- and /* */ comments and collapses all whitespace to single spaces, leaving quoted text untouched.Embedding a query in a string literal, a JSON field, a shell command or a single log line.

Clause-per-line beautifier

The clause style inserts a line break before SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, JOIN and its LEFT / RIGHT / INNER / FULL / CROSS variants, UNION, INSERT INTO, VALUES, UPDATE, SET and DELETE FROM. Only whole words are matched, so a column like order_total is safe, and text inside quotes is never split. With Keyword case: Preserve your original casing is kept exactly — select stays select.

select id, name from users where active = 1 order by name;

-- clause per line, case preserved
select id, name
from users
where active = 1
order by name;

Supported dialects

Picking the right dialect matters for the Indented style: it decides which quote characters delimit identifiers and which words are keywords. If you get a parse error, try Standard SQL or switch to Clause per line.

Minify SQL

Minify strips comments before joining lines, so -- note at the end of a line cannot comment out the rest of the query once it is on one line. Strings in 'single', "double" or `backtick` quotes, including doubled-quote escapes like 'it''s', are copied exactly.

Common questions

How do I format a SQL query online?

Paste your SQL into the input box, pick a dialect and keyword case, then click Format. The query is reformatted with indentation and line breaks entirely in your browser. A separate Minify button collapses it back to one line.

What is the difference between the Indented and Clause per line styles?

Indented parses the query and lays it out fully: select lists one column per line, JOIN conditions and subqueries indented. Clause per line is a lighter SQL beautifier that only collapses whitespace and starts each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY and so on) on a new line, keeping your casing and never failing on unusual syntax.

Should keywords be uppercase or lowercase?

UPPERCASE is the traditional convention and aids visual parsing. Some modern style guides prefer lowercase. Both are valid; pick one and stay consistent. Choose Preserve to leave your original casing.

How do I minify SQL to a single line?

Paste the query and click Minify. Line breaks and indentation collapse to single spaces, and -- and /* */ comments are removed first, so a line comment cannot swallow the rest of the query. Text inside quotes is left exactly as it is.

Does this tool execute SQL?

No. It only formats the text. It does not connect to any database and does not validate table or column names.

Is my query uploaded?

No. Formatting runs in your browser and the query never leaves the page.