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:
- Quoted identifiers stay intact:
`backticks`in MySQL, MariaDB and BigQuery,[square brackets]in SQL Server,"double quotes"in PostgreSQL, Oracle and the standard. - Dialect operators are recognised: PostgreSQL
::casts and JSON operators->and->>,$1parameters and$$dollar-quoted function bodies; T-SQL@variables,#temptables andGObatch separators; Oracle:bindvariables. - Dialect keywords are cased correctly:
QUALIFYin Snowflake and BigQuery,ILIKEin PostgreSQL,TOPin SQL Server,LIMITversusFETCH FIRST.
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
- Keywords — UPPER is the most common convention because it separates SQL from your table and column names. Lower case is popular in dbt and analytics teams. Keep as typed only re-indents.
- Functions — case for function names such as
count(),coalesce()anddate_trunc(). - Style — Standard puts each clause keyword on its own line with the content indented below it. Tabular styles put the keyword and its content on one line in a fixed-width column, either left-aligned or right-aligned to form a “river” in the style many SQL style guides recommend.
- AND/OR — at the start of the line (easy to comment out one condition) or at the end.
- Inline up to — short parenthesised expressions such as
IN ('paid', 'shipped')stay on one line up to this many characters. - Blank lines between queries, dense operators (
a=binstead ofa = b) and semicolon on its own line.
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
- Write one clause per line and one column per line in long select lists, so code reviews and diffs show exactly which column changed.
- Use meaningful table aliases (
customers c,orders o) and always qualify columns in joins. - Prefer common table expressions (
WITH … AS) to deeply nested subqueries. - Name columns explicitly instead of
SELECT *in production code. - Never build SQL by joining strings with user input. Use parameterised queries, as the OWASP SQL Injection Prevention Cheat Sheet recommends. Formatting makes code readable; it does not make it safe.
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
- ISO/IEC, ISO/IEC 9075-2:2023 — SQL/Foundation, the current SQL standard, with Technical Corrigendum 1:2026.
- PostgreSQL Global Development Group, SQL Syntax — Lexical Structure (identifiers, quoting, dollar quoting, comments).
- Oracle, MySQL 8.4 Reference Manual — Schema Object Names (backtick quoting).
- Microsoft Learn, Database identifiers (SQL Server) (bracket quoting).
- OWASP, SQL Injection Prevention Cheat Sheet.
- sql-formatter (MIT licence), the formatting engine, bundled locally with this page.
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.