⚡Free Tools

SQL Formatter & Beautifier

Format messy SQL into clean, readable queries for 20 database dialects, with UPPER or lower keywords, tabular layouts, one-line minify and a check that only whitespace and case changed. Private: nothing is uploaded.

More layout options
Input SQL
Formatted SQL

A SQL beautifier that knows your database

Paste a query — a one-line statement copied from an application log, an ORM debug dump, a stored procedure or a whole .sql migration — choose your database and press Format SQL or Ctrl+Enter. Every clause starts on its own line, the select list and join conditions are indented, CASE expressions and subqueries are laid out so you can follow them, and keywords are written in UPPER case (or lower case, or kept exactly as you typed them). Twenty dialects are supported: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark SQL and Databricks, Hive, Trino/Presto/Athena, DuckDB, ClickHouse, IBM Db2 and Db2 for i, SingleStoreDB, TiDB and Couchbase N1QL.

The formatter runs entirely in your browser using the open-source sql-formatter library, bundled with this page. Queries often contain table names, customer IDs, email addresses or business logic you should not paste into a random website — here nothing is uploaded, logged or stored on a server, and the page keeps working offline once loaded.

Why the dialect matters

SQL is defined by the ISO/IEC 9075 standard, but every database extends it and quotes things differently. If the formatter does not know your dialect, it can split an operator in half or treat a quoted name as a string. Choosing the right one means:

Not sure which dialect a query was written for? If the formatter spots tell-tale syntax — brackets and TOP for SQL Server, :: casts for PostgreSQL, NVL and DUAL for Oracle — it suggests a switch with one click.

A built-in safety check

A formatter should never change what a query does. After each run this tool compares the input and output token by token, ignoring whitespace and letter case. If they match you see “Only whitespace and letter case changed ✓”. If anything else differs, you get a warning to review the result before running it against a production database. String literals are never re-cased — 'Paid' stays 'Paid'.

Layout options explained

Your options are remembered in this browser, so the formatter matches your team style next time.

Minify SQL to a single line

Minify joins the query into one line for a log entry, a JSON payload, a shell command or a code string. It is token-aware, so strings, quoted identifiers and dollar-quoted bodies are never touched, and a space is kept wherever removing it would merge two words or turn - -1 into a -- comment. Line comments are dropped, because a -- comment on a single line would comment out the rest of the query. If you untick Minify removes comments, they are converted into /* … */ block comments instead. Optimizer hints written as /*+ … */ are kept. Multiple statements each get their own line.

Statistics you can use

Under the output you see the number of statements and their types (for example SELECT ×2, UPDATE ×1), the tables referenced after FROM, JOIN, INTO and UPDATE, the line count and the size. This is a quick way to see what a long migration or report query touches before you run it.

Error messages

When the parser cannot read a query, you get the line and column, a snippet with a caret under the problem, and a Go to error button. The usual causes are an unclosed bracket or quote, a missing END after CASE, a stray comma before FROM, or syntax from a different dialect — try switching the dialect first.

SQL style tips

Privacy, offline use and limits

Everything runs locally. Drafts, your options and the last 12 inputs are kept only in this browser's localStorage, and you can clear them from the History dialog. The formatter handles files of several thousand lines. It formats SQL; it does not run queries or check that tables and columns exist. Procedural blocks (PL/pgSQL, T-SQL control flow, PL/SQL packages) are formatted as statements, so very long procedures may need some manual touch-up.

Sources and references

Frequently asked questions

Is my SQL sent to a server?

No. The formatter runs in your browser with a locally bundled copy of the open-source sql-formatter library. Nothing is uploaded or logged, and it works offline after the page loads.

Can formatting change what my query does?

It should only change whitespace and keyword case. The tool verifies this after every run by comparing tokens, and warns you if anything else differs. String literals are never re-cased.

Which databases are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark SQL, Hive, Trino/Presto/Athena, DuckDB, ClickHouse, IBM Db2, Db2 for i, SingleStoreDB, TiDB and Couchbase N1QL.

Why do I get a parse error?

Usually an unclosed bracket or quote, a missing END after CASE, a trailing comma before FROM, or syntax from another dialect. Check the line shown, and try switching the dialect.

How does minify handle -- comments?

A -- comment would swallow the rest of a one-line query, so minify removes comments by default. If you keep comments, they are converted to /* */ block comments. Optimizer hints /*+ */ are kept.

Does it validate tables and columns?

No. It formats SQL text and does not connect to a database, so it cannot know whether a table or column exists.

Keyboard shortcuts

Ctrl + EnterFormat SQL
Ctrl + Shift + MMinify to one line
Ctrl + Shift + CCopy output
Ctrl + SDownload .sql