Skip to content
JustTools

SQL Formatter

Paste a query and get it neatly indented, with keywords in the case you like — or squeezed onto one line.

Runs in your browser Free · no sign-up

At a glance

  • Formats queries for 11 dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite, BigQuery, Snowflake, Redshift and Spark SQL — with each one’s quoting and operators.
  • Puts every clause on its own line, indents joins and conditions, and keeps comments where they belong.
  • Choose UPPER, lower or original case for keywords, functions and types; 2 or 4 spaces or tabs; a standard or tabular layout; and AND/OR at the start or end of lines.
  • Minify to a single line without comments — strings, quoted names and dollar-quoted bodies are never touched.
  • Syntax-coloured output with line numbers, clear error messages with the line and column, and copy or download as .sql.
  • Runs in your browser — your queries, table names and data never leave your device.

Step by step

How to format SQL online

  1. 1

    Paste your query

    Paste SQL into the left box or open a .sql file.

  2. 2

    Pick the dialect

    Choose your database so its syntax is understood.

  3. 3

    Set your style

    Choose the keyword case, indentation and layout.

  4. 4

    Copy the result

    Copy the formatted SQL or download it — or switch to Minify for one line.

Features

Everything you need, nothing you don’t

11 SQL dialects

From MySQL and PostgreSQL to T-SQL, PL/SQL and BigQuery.

Your style

Keyword case, indentation, layout and operator spacing.

Minify

One line, comments removed, strings left intact.

Errors pinpointed

The line and column that couldn’t be parsed.

Files

Open .sql files; copy or download the result.

Private

Queries stay on your device.

Before and after

select o.id, sum(i.qty*i.price) total from orders o join order_items i on i.order_id=o.id where o.status='paid' group by o.id order by total desc becomes a query with SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY each on their own line and their contents indented beneath — far easier to read, review and debug.

Common SQL style choices

ChoiceWhy
UPPER-CASE keywordsSeparates the SQL language from your table and column names at a glance.
One clause per lineDiffs and code reviews show exactly what changed.
AND / OR at line startEasy to comment out or reorder conditions.
Tabular layoutLines keywords up in a column, popular in data teams.
MinifiedFor embedding in code, logs, or URLs where whitespace gets in the way.

FAQ

Frequently asked questions

Is my SQL sent to a server?

No. Formatting happens in your browser, so queries containing table names, customer data or credentials stay on your device.

Which SQL dialect should I choose?

The database you run the query on. Dialects differ in quoting ([name] in SQL Server, name in MySQL), operators (->> in PostgreSQL) and keywords; Standard SQL works for most simple queries.

Why do I get a parse error?

The formatter needs SQL it can read: check for an unclosed bracket or quote near the line shown, or try another dialect if the query uses database-specific syntax.

Does it change what my query does?

No. Only whitespace and the case of keywords change. Strings, quoted names and comments stay exactly as written (minifying removes comments).

Can it format stored procedures and several statements?

Yes — paste several statements separated by semicolons; each is formatted and separated by a blank line. Procedural code is formatted best with the matching dialect (T-SQL or PL/SQL).

What library does it use?

The open-source sql-formatter library (MIT licence) for formatting; minifying and colouring are our own.

Keep going

Browse every tool

Last updated Report a problem or suggest a feature