Skip to content
wonderstacked

SQL Formatter

Format and indent SQL for any major database.

Runs in your browser
Loading SQL Formatter…

How do I format SQL?

A SQL formatter indents and lays out queries so they are easy to read and review. This SQL formatter supports PostgreSQL, MySQL, SQL Server, BigQuery, Snowflake, Oracle and more, and can minify a query to one line.

Generated or pasted SQL often arrives as a single line, which makes joins and subqueries hard to follow. Formatting puts each clause on its own line, indents nested queries and aligns keywords, so mistakes show up in review.

Pick the dialect so dialect-specific syntax is understood, such as BigQuery backticks or SQL Server brackets. You can choose uppercase or lowercase keywords and the indent size, and minify a query to a single line for logs or config. The sql-formatter library runs locally in your browser.

The formatter changes layout only, never the meaning of the query. It does not validate the query against a database or catch logic errors, and very unusual syntax may not format perfectly.

Page updated .

How to use the SQL Formatter

  1. Paste your SQL.
  2. Choose the dialect, keyword case and indentation.
  3. Copy the formatted query, or minify it.

Examples

Format
Input
select id,name from users where active=1 order by name
Output
SELECT, FROM, WHERE and ORDER BY each on their own line
Minify
Input
A formatted multi-line query
Output
One line with single spaces

Tips

  • Pick the right dialect first; the wrong one can mis-handle quoting.
  • Use uppercase keywords if your team style guide asks for them.
  • Minify only for transport; keep readable SQL in source control.

Specs & limits

Dialects
PostgreSQL, MySQL, SQL Server, BigQuery, Snowflake, Oracle and more
Options
Keyword case, indentation, minify
Library
sql-formatter (MIT)
Execution
None
Processing
In your browser

Troubleshooting

›Parse error

Cause: Syntax the dialect does not accept.

Fix: Choose another dialect.

›Comments moved

Cause: Comment placement is normalised.

Fix: Check comments after formatting.

›Long lines remain

Cause: Long expressions are not wrapped.

Fix: Break them manually.

Frequently asked questions

›Does formatting change what the query does?

No. Only whitespace and optionally keyword case change.

›Which databases are supported?

PostgreSQL, MySQL, MariaDB, SQL Server, BigQuery, Snowflake, Oracle PL/SQL, SQLite and others.

›Can it check my SQL for errors?

It reports syntax it cannot parse but does not run the query or validate against a schema.

›Is my query uploaded?

No. Formatting runs in your browser.

›Can I minify SQL?

Yes, to a single line.

›Why is formatting slightly different from my editor?

Tools have different style rules. Pick the options that match your team.

More developer tools

See all
esc