Back to All Tools

SQL Formatter

Format and prettify SQL queries across PostgreSQL, MySQL, SQLite, T-SQL, BigQuery and more.

Runs entirely in your browser — nothing is uploaded

About the SQL Formatter

SQL Formatter takes a query you have squashed onto one line, or one copied out of an ORM log with no line breaks, and rewrites it into indented, readable SQL. It handles the common problem of inheriting a 200-character SELECT with nested joins and no whitespace, where you cannot tell which condition belongs to the WHERE clause and which belongs to the JOIN. Paste the query, pick the dialect, and get structured output you can review.

The tool is built on the sql-formatter library, loaded in your browser only when you press Format. You paste SQL into the Query box, choose one of 14 dialects, and set the tab size to 2, 4, or 8 spaces. It re-indents clauses, breaks long statements, and uppercases keywords like SELECT, FROM and WHERE. If the input cannot be parsed, it shows the error instead of silently producing garbage.

It is free and needs no account or sign-in. The formatting runs entirely in your browser through a dynamically imported library, so the query you paste never leaves your machine or hits a server. That matters when the SQL contains real table names or literal values from a production database. A Copy button on the result sends the formatted query back to your editor in two clicks.

How to use the SQL Formatter

  1. 1Paste or type your SQL into the Query box, replacing the sample query that loads by default.
  2. 2Click the button for your database dialect, such as postgresql, mysql, bigquery or tsql.
  3. 3Set the Tab size dropdown to 2, 4, or 8 spaces to match your project's indentation.
  4. 4Press the Format button and wait for the formatter to load and run.
  5. 5Read the result in the Formatted box, then click Copy to put it on your clipboard.
  6. 6Use Clear to empty both boxes before pasting a different query.

What you can use it for

Reading ORM query logs

Frameworks like Prisma, Django or ActiveRecord print generated SQL as one unbroken line. Paste that log line here, pick the matching dialect, and see the joins and filters laid out so you can spot the missing index or accidental cross join.

Cleaning up before code review

A teammate submits a migration with a query mashed onto one line. Format it with your project's tab size before the review so the diff shows a readable statement and the reviewer can follow the WHERE and GROUP BY clauses.

Standardizing keyword case

You have a stored procedure where keywords are a mix of lowercase select and uppercase FROM. Running it through the formatter rewrites every keyword to uppercase in one pass, giving the file a consistent style without hand editing.

Matching dialect quirks

A BigQuery or Snowflake query with backticks and dialect-specific functions gets mangled by a generic formatter. Select the exact dialect button first so the formatter respects that engine's syntax.

Frequently asked questions

Does my SQL get sent to a server?

No. The formatter library is imported into your browser when you click Format, and the formatting happens locally. The query text stays on your device, so table names, column names and any literal values in the SQL are never uploaded. You can confirm this by formatting a query with your network disconnected after the page has loaded.

Which database dialects are supported?

Fourteen: sql, postgresql, mysql, mariadb, sqlite, tsql, bigquery, redshift, snowflake, trino, spark, db2, hive and plsql. Postgresql is selected by default. Picking the right one matters because dialects differ on quoting, functions and keywords, and the wrong choice can misformat engine-specific syntax.

Can I keep my keywords in lowercase?

No. The formatter is set to uppercase all SQL keywords, so SELECT, FROM, WHERE and JOIN always come out capitalized regardless of how you typed them. There is no toggle to preserve lowercase or pick a different case. If your style guide requires lowercase keywords, this tool will not match it.

What tab size options does the SQL formatter offer?

The Tab size dropdown offers 2, 4, or 8 spaces. Indentation uses spaces, not tab characters, and there is no option for tabs. Two spaces is the default. Change it before pressing Format, since the setting is applied when the query is processed.

Why do I get an error message instead of output?

The formatter parses the SQL before reformatting it. If the statement has syntax it cannot parse, or the selected dialect does not match, it throws and shows that error in a red box instead of producing output. Check that the dialect matches your query and that the SQL is complete.

Does it check whether my query is correct?

No. This is a formatter, not a linter or validator. It re-indents and reflows the text and uppercases keywords, but it does not run the query, check that tables or columns exist, or warn about logic errors. A query that formats cleanly can still fail when your database runs it.