SQL Formatter & Beautifier
Beautify or minify SQL in 20 dialects — keyword and identifier case, indent width and style, comment removal, Python/PHP string output. All in your browser.
Ln 1, Col 1
-- active customers and how much they ordered SELECT u.id, u.name, count(o.id) AS order_count FROM users u JOIN orders o ON o.user_id = u.id WHERE u.active = 1 AND u.country = 'NL' GROUP BY u.id, u.name ORDER BY order_count DESC;
🔒 Formatted in your browser — nothing is uploaded.
Beautify or minify, in 20 dialects
Paste a query, or open a .sql file from disk (up to 5 MB), and the result re-formats as you type — there is no Format button to press. Beautify gives consistent indentation and line breaks before the major clauses (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY). Minify collapses the query onto a single line: comments go and every run of whitespace outside a string literal becomes one space, while no token is reordered or rewritten — a PostgreSQL $$…$$ body and a MySQL backslash escape come through exactly as written. Formatting is powered by the widely used sql-formatter engine, and you can pick any of the 20 dialects it knows: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Amazon Redshift, Snowflake, IBM DB2 (LUW), IBM DB2 for i, Apache Hive, Spark SQL, Trino/Presto, ClickHouse, DuckDB, TiDB, SingleStore and Couchbase N1QL. The dialect decides more than layout — the comment markers come from its own lexer, so # opens a comment in BigQuery and MySQL, // does in Snowflake, and # stays an operator in PostgreSQL.
Every part of the layout is a control
Keywords and identifiers each have their own case setting — UPPERCASE, lowercase, Capitalized, or left unchanged — and string literals are never recased. Indent with 2 spaces, 4 spaces or a tab, in Standard, Tabular left or Tabular right style. Remove comments is off by default, so nothing is deleted unless you ask for it; when it is on, a comment marker inside a string literal is left alone and each removed comment leaves behind the line breaks it spanned, so the lines below it keep their numbers. A live Ln 3, Col 12 readout sits under the input, and when the parser cannot read the query you get one sentence naming the line and column it stopped at, in the language of the page.
Take the result away
Hand the query over as SQL, or as a Python or PHP string literal ready to paste into code: one quoted piece per line with the line breaks written into the literal, and quotes, backslashes and — for PHP — $ escaped. Copy it or download it; a file opened as monthly.sql is saved back as monthly.sql, monthly.py or monthly.php, and a query you pasted as formatted.sql, minified.sql, query.py or query.php.
Why formatting matters
Readable SQL is easier to review, debug and hand off. A well-indented query makes it obvious which conditions belong to which clause and where a join or subquery begins and ends, which helps catch mistakes like a misplaced AND or a missing GROUP BY column. Consistent formatting also makes code reviews and version-control diffs smaller and clearer. The whole thing runs in your browser, so queries that reference real table and column names never leave your machine.
Frequently asked questions
Which SQL dialects are supported?
All 20 the sql-formatter engine knows: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Amazon Redshift, Snowflake, IBM DB2 (LUW), IBM DB2 for i, Apache Hive, Spark SQL, Trino/Presto, ClickHouse, DuckDB, TiDB, SingleStore and Couchbase N1QL. The choice decides more than layout — comment markers are read from that dialect's own lexer, so # is a comment in BigQuery and MySQL, // is one in Snowflake, and # stays an operator in PostgreSQL.
Does it change what my query does?
Beautify only moves whitespace and recases keywords; Minify moves whitespace and drops comments. No token is reordered or rewritten and string literals are copied verbatim, so the query runs the same. Two settings do change text, and only when you pick them: Remove comments deletes the comments, and the Identifiers case setting recases unquoted table and column names — which matters on systems where those names are case-sensitive. Leave Identifiers on Unchanged if you are unsure.
Is my SQL sent to a server?
No. Formatting happens entirely in your browser. Your query, including any table or column names, never leaves your device and is not stored.
Can I minify a query onto one line?
Yes — switch Mode to Minify. Comments go and every run of whitespace outside a string literal becomes a single space; nothing else moves. A PostgreSQL $$…$$ body, a MySQL backslash escape and the spaces inside a quoted string all survive untouched. The casing and indent options do not apply in this mode, because minifying never rewrites a token.
Can I get the formatted query as a Python or PHP string?
Yes. Set Output to Python string or PHP string and the result comes out as a literal you can paste straight into code — one quoted piece per line, with quotes and backslashes escaped and $ escaped as well for PHP. The download follows the choice: query.py or query.php, or the name of the file you opened with that extension.
Can I open a .sql file instead of pasting?
Yes. Open file accepts a .sql or .txt up to 5 MB and reads it in the browser — the file is never uploaded. The download that follows is named after it, so opening monthly.sql saves monthly.sql back (or monthly.py / monthly.php if you changed the output syntax).
What does the Capitalized case option do?
It writes each word of that class with the first letter up and the rest down — Select, From. The formatter engine has no such setting, so the tool derives it: the query is formatted twice, once upper and once lower, and exactly the words the two renderings disagree about are capitalized. That makes it precise for both keywords and identifiers and leaves names, numbers and string literals alone.
What happens if my query cannot be parsed?
Instead of the library's English list of grammar rules you get one sentence naming the line and column the parser stopped at, written in the language of the page. The live Ln/Col readout under the input box lets you move the caret to that exact spot.