SQL Formatter

Format and beautify a SQL query with indented clauses and uppercase keywords, or minify it to a single line.

Mode

Paste or type a SQL query above to beautify or minify it.

No uploads. Your files stay on your device.

Free forever, no sign-up, no cookies. Buy me a coffee

How it works

Paste a query and it is re-printed instantly. Format gives you readable SQL: every major clause — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, VALUES — starts on its own line with its columns and conditions indented underneath, each item in a comma-separated list gets its own line, JOIN lines are lined up with FROM with their ON condition indented, and AND / OR conditions are stacked so a long WHERE clause is easy to scan. Sub-queries in parentheses are indented one level deeper. Choose 2-space, 4-space or tab indentation, and whether keywords are UPPERCASED, lowercased or left exactly as you typed them. Minify does the opposite: comments are dropped and the whole statement is squeezed onto one line — handy for pasting a query into a log, a config file or a string literal.

The formatter is a real SQL tokenizer, not a search-and-replace: string literals, quoted and back-ticked identifiers, -- line comments, # comments and /* … */ block comments are preserved byte-for-byte, so nothing inside quotes is ever re-cased or re-indented. Table names, column names and function names keep the casing you wrote. Multiple statements separated by semicolons are formatted one after another with a blank line between them. Unterminated strings, unterminated comments and unbalanced parentheses are reported with the line number instead of producing mangled output.

Everything runs in your browser in plain JavaScript — your query is never uploaded, logged or sent to a server, which matters when the SQL contains table names, schema details or literal values from a production database. Use Copy SQL or Download .sql to take the result with you.

Frequently asked questions

How do I format SQL online for free?

Paste your query into the box above. It is beautified as you type: every clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY) starts on its own line, columns and conditions are indented beneath it, JOINs line up with FROM and sub-queries are indented one level deeper. Choose 2-space, 4-space or tab indentation and whether keywords are UPPERCASED, lowercased or left as typed, then hit Copy SQL or Download .sql. There is no signup, no ad wall and no limit on how many queries you format.

Is it safe to paste SQL into an online formatter?

With most SQL formatters, no — they POST your query to a server, so your table names, column names and any literal values in the WHERE clause leave your machine. This one is different: the tokenizer and formatter are plain JavaScript that run inside your browser tab. Nothing is uploaded, logged or stored, and the page keeps working with your network disconnected, which you can verify in your browser's DevTools network panel.

Which SQL dialects does this formatter support?

It is dialect-agnostic and works with MySQL, PostgreSQL, SQL Server (T-SQL), SQLite, Oracle, Snowflake and BigQuery. It formats standard clauses, JOINs, sub-queries, CTEs, INSERT/UPDATE/DELETE and multi-statement scripts separated by semicolons. Because it is a real tokenizer, string literals, double-quoted and back-ticked identifiers, and --, # and /* */ comments are preserved byte-for-byte, and dialect-specific keywords it does not recognise are simply left exactly as you wrote them.

Report a bug